android-preferences

Android preferences - what is the difference?

我与影子孤独终老i 提交于 2019-11-30 06:34:07
问题 What is the difference, when I get preferences as: PreferenceManager.getDefaultSharedPreferences(getBaseContext()); and getPreferences(Context.MODE_PRIVATE); 回答1: PreferenceManager.getDefaultSharedPreferences(getBaseContext()); Will provide an access to a preferences file that is global for the whole application package ; any activity can access the preferences (internaly, the xml file holding the preferences will be named your.application.package_preferences.xml ). contextInstance

Best option to store username and password in android app

断了今生、忘了曾经 提交于 2019-11-30 06:20:43
问题 I am developing an Android app where the user needs to sign in to perform operations. But mostly on an android handset, people use "Keep me signed in" , In that case, I'll have to maintain the value of Username and Password within my app. Should I use SharedPreferences , or SQLite Database or is there something else which I can use. And how can I make it secure? 回答1: Yes, this is tricky on Android. You don't want to store the plaintext password in the preferences, because anyone with a rooted

Why SwitchPreference is not showing animation when switching from on to off & vice versa?

社会主义新天地 提交于 2019-11-30 05:17:44
I've made a SwitchPreference for my app's preferences . The problem is that the SwitchPreference is not showing animation when I'm switching between on & off, rather, it is switching with a sudden jerk. Here's preferences.xml file's code: <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <SwitchPreference android:id="@+id/notification" android:key="notification" android:title="@string/notification" android:defaultValue="true"/> </PreferenceScreen> I'm a beginner, so please cooperate & let me know what's wrong here. Thanks in

android set divider padding for preference screen

拜拜、爱过 提交于 2019-11-30 04:08:56
问题 I have PreferenceScreen contain many CheckBox , i customize it by refer it to custom layout as bellow : <?xml version="1.0" encoding="utf-8" ?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <CheckBoxPreference android:summary="checkbox one" android:key="key_one" android:layout="@layout/mylayout" /> <CheckBoxPreference android:summary="checkbox two" android:key="key_two" android:layout="@layout/mylayout" /> </PreferenceScreen> mylayout.xml: <LinearLayout xmlns

Get preferences in AppWidget Provider

两盒软妹~` 提交于 2019-11-30 04:02:48
I seem to be having trouble reading preferences from my AppWidgetProvider class. My code works in an Activity, but it does not in an AppWidgetProvider. Here is the code I am using to read back a boolean: SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); boolean autoreplyon = settings.getBoolean("autoreplyon", false); However, I get the "The method getSharedPreferences(String, int) is undefined for the type widget" error (widget is the name of my AppWidgetProvider class). Thanks in advance for any suggestions! getSharedPreferences() , should you choose to use it, is only

Setting UI preference Summary field to the value of the preference

匆匆过客 提交于 2019-11-30 01:40:45
New to Android, I have some code when the user changes a preference I update the Summary field in the UI preference to be the value they entered. However, when the preference activity is created I'd like to set the Summary fields to be the values in the corresponding preferences. Please advise. Thanks. public class MyPreferenceActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference); SharedPreferences sp = getPreferenceScreen()

SharedPreferences.getInt() results in ClassCastException - Why?

倖福魔咒の 提交于 2019-11-30 00:38:08
问题 I have a simple (not user-editable) numerical setting defined in a preferences XML as follows: <EditTextPreference android:key="@string/numeric_val" android:defaultValue="0" /> And I read it using this simple statement: sharedPrefs.getInt(getString(R.string.numeric_val), 3) It works, but when I try to read it, for the first time after application install , it generates a ClassCastException . The documentation says that getInt() "Throws ClassCastException if there is a preference with this

Nested preferences.xml

三世轮回 提交于 2019-11-29 22:55:34
Is it somehow possible to include one preferences.xml into another, like it can be done for layouts with the <include /> tag? Let's say: <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen android:title="@string/pref_group_title_visual"> <include preferences_filename="xml/pref_visual"/> </PreferenceScreen> ... Solution here it is to inflate both preference files from PreferencesActivity. For example: addPreferencesFromResource(R.xml.options); addPreferencesFromResource(R.xml.additional_options); The solution

How to show and hide preferences on Android dynamically?

烂漫一生 提交于 2019-11-29 22:15:02
Is there a way to dynamically show and hide preferences? In my case, I have a checkbox preference that would disable or enable one of 2 preference groups ("with-" and "without-handicap" groups). While this would be the ideal GUI in a desktop environment, the "with-handicap" takes up nearly the whole screen, while the other, "without-handicap" takes up only a small portion of the screen. Rather than showing both groups at the same time, I'd like to show only one of them at a time, and dynamically show or hide the 2 groups when the checkbox changes. Is there a way to do this? dhaag23 From a

HowTo use support.v7.preference with AppCompat and potential drawbacks

我与影子孤独终老i 提交于 2019-11-29 21:05:25
I was trying to implement preferences for an AppCompat app, using support.v7.preference. It took me a couple of days to fiddle through it, since support.v7.preference has some significant differences to the native preferences... which isn't too bad once you know, but unfortunately there's little documentation out there. I thought I'd share my findings so others don't have to go through the same pain. So... question: How do you best implement Preferences for AppCompat apps (with PreferenceFragment and AppCompatAcitivity being incompatible)? Here are a couple of related questions: Preference sub