Questions tagged [android-preferences]

1916 questions
476
votes
35 answers

How do I display the current value of an Android Preference in the Preference summary?

This must come up very often. When the user is editing preferences in an Android app, I'd like them to be able to see the currently set value of the preference in the Preference summary. Example: if I have a Preference setting for "Discard old…
nyenyec
  • 7,138
  • 9
  • 29
  • 15
293
votes
8 answers

SharedPreferences.onSharedPreferenceChangeListener not being called consistently

I'm registering a preference change listener like this (in the onCreate() of my main activity): SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener( new…
synic
  • 26,359
  • 20
  • 111
  • 149
233
votes
6 answers

Difference between getDefaultSharedPreferences and getSharedPreferences

What is the difference between getDefaultSharedPreferences and getSharedPreferences in Android? Can anyone please explain?
James
  • 2,383
  • 2
  • 14
  • 6
155
votes
10 answers

How to add a button to a PreferenceScreen?

I'm quite new to Android Development and just came across Preferences. I found PreferenceScreen and wanted to create a login functionality with it. The only problem I have is that I don't know how I could add a "Login" button to the…
Van Naaktgeboren
  • 1,551
  • 2
  • 10
  • 4
121
votes
6 answers

how to remove shared preference while application uninstall in android

I have an android application to save the login details such as user name and password via SharedPreferences thats works fine, but i need to remove all my used SharedPreferences while my application uninstall. How to do it? SavePreferences("one ",…
shivcena
  • 2,023
  • 8
  • 24
  • 50
119
votes
3 answers

How to implement a confirmation (yes/no) DialogPreference?

How can I implement a Preference that displays a simple yes/no confirmation dialog? For an example, see Browser->Setting->Clear Cache.
sh1ng
  • 2,808
  • 4
  • 24
  • 38
118
votes
5 answers

Android preferences onclick event

In my preferences.xml I have a preference element like this: I want to assign onClick event, so if user would click on it, I would be able to do open new Intent or browser. I tried to do it like I do with…
Badr Hari
  • 8,114
  • 18
  • 67
  • 100
111
votes
12 answers

How to add a button to PreferenceScreen

Is there any way to add a button to the bottom of preferences screen and make them work correct when scrolling?
vlaku
  • 1,534
  • 2
  • 14
  • 27
98
votes
10 answers

How to listen for preference changes within a PreferenceFragment?

As described here, I am subclassing PreferenceFragment and displaying it inside an Activity. That document explains how to listen for preference changes here, but only if you subclass PreferenceActivity. Since I'm not doing that, how do I listen for…
87
votes
11 answers

Is it possible to add an array or object to SharedPreferences on Android

I have an ArrayList of objects that have a name and an icon pointer and I want to save it in SharedPreferences. How can I do? NOTE: I don't want to use Database
zsniperx
  • 2,732
  • 6
  • 25
  • 32
87
votes
7 answers

How to get all keys of SharedPreferences programmatically in Android?

How to get all keys in SharedPreferences, not the value of the preference just key only? prefA = getSharedPreferences("MyAttack", MODE_PRIVATE); prefB= getSharedPreferences("MySkill", MODE_PRIVATE);
Piolo Opaw
  • 1,471
  • 2
  • 15
  • 21
85
votes
4 answers

how to use getSharedPreferences in android

I have an application in which I have to implement a "Login" activity. I have these components: EditText username EditText password Button Login Button Cancel I want that my application to remember the login details of the user once the user has…
CMA
  • 2,758
  • 5
  • 28
  • 40
79
votes
9 answers

TimePicker in PreferenceScreen

I'd like to create a preference field called Interval and I want to be able to popup a TimePicker and set a mm:ss formated value with minimal value 00:30 and step 30 seconds. Is it possible to use TimePicker in PreferenceScreen ?
hsz
  • 148,279
  • 62
  • 259
  • 315
78
votes
6 answers

Misbehavior when trying to store a string set using SharedPreferences

I'm trying to store a set of strings using the SharedPreferences API. Set stringSet = sharedPrefs.getStringSet("key", new HashSet()); stringSet.add(new_element); SharedPreferences.Editor editor =…
JoseLSegura
  • 3,830
  • 3
  • 20
  • 27
77
votes
2 answers

How to detect if changes were made in the preferences?

I have a class that extends PreferenceActivity and shows the preference screen of my app. Is it possible to check if any changes were made to the preferences? This…
mixkat
  • 3,883
  • 10
  • 40
  • 58
1
2 3
99 100