Questions tagged [sharedpreferences]

SharedPreferences allows you to save and retrieve persistent key-value pairs of primitive data types in Android applications. It can be used either inside a single app or shared between multiple apps.

SharedPreferences allows you to save and retrieve persistent key-value pairs of primitive data types in Android applications. It can be used either inside a single app or shared between multiple apps.

You can learn more about SharedPreferences under the Data Storage section in the Android documentation.

7696 questions
123
votes
33 answers

Flutter: Unhandled exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)

My Flutter application uses the Flutter SharedPreferences plugin and send values to the iOS side with platform.invokeMethod. If I start the application, I have this error: [VERBOSE-2:dart_error.cc(16)] Unhandled exception: MissingPluginException(No…
camilleB
  • 1,961
  • 4
  • 15
  • 20
113
votes
12 answers

store and retrieve a class object in shared preference

In Android can we store an object of a class in shared preference and retrieve the object later? If it is possible how to do it? If it is not possible what are the other possibilities of doing it? I know that serialization is one option, but I am…
androidGuy
  • 5,553
  • 12
  • 39
  • 56
108
votes
6 answers

How to remove some key/value pair from SharedPreferences?

How to remove some key/value pair from SharedPreferences ? I have put and I to remove that from prefs.
Damir
  • 54,277
  • 94
  • 246
  • 365
107
votes
12 answers

How to save HashMap to Shared Preferences?

How can I save a HashMap Object into Shared Preferences in Android?
jibysthomas
  • 1,601
  • 2
  • 16
  • 24
101
votes
12 answers

Android SharedPreferences in Fragment

I am trying to read SharedPreferences inside Fragment. My code is what I use to get preferences in any other Activity. SharedPreferences preferences = getSharedPreferences("pref", 0); I get error Cannot make a static reference to the…
Mark
  • 1,073
  • 2
  • 10
  • 9
100
votes
6 answers

Can't put double SharedPreferences

Getting error, the method put double is undefined for this type of sharedPreferences editor.Eclipse is given one quick fix add cast to editor, but when i do that its still given errors, Why cant i put double. The code: @Override protected void…
Robert
  • 1,107
  • 2
  • 8
  • 8
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…
92
votes
3 answers

What will happen to the SharedPreferences on update an Android App?

I've stored user settings in the SharedPreferences in my App. What will happen with the SharedPreferences when I update the App via Google Play Store to a new version of the App? Will the SharedPrefernces still be there after the update or will they…
Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
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
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
82
votes
4 answers

How to iterate through all keys of shared preferences?

SharedPreferences have method getAll, but it returns no entries despite the fact some keys exist: PreferenceManager.getDefaultSharedPreferences(this).contains("addNewAddress"); returns true Map
Eugene Chumak
  • 3,272
  • 7
  • 34
  • 52
80
votes
8 answers

Android ArrayList of custom objects - Save to SharedPreferences - Serializable?

I have an ArrayList of an object. The object contains the types 'Bitmap' and 'String' and then just getters and setters for both. First of all is Bitmap serializable? How would I go about serializing this to store it in SharedPreferences? I have…
Paul Blundell
  • 1,857
  • 4
  • 22
  • 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
76
votes
9 answers

onSharedPreferenceChanged not fired if change occurs in separate activity?

I've implemented onSharedPreferenceChanged in my main activity. If I change the preferences in the main activity, my event fires. If I change the preferences through my preferences screen (PreferenceActivity) my event does NOT fire when…
Brad Hein
  • 10,997
  • 12
  • 51
  • 74
71
votes
11 answers

How to Secure Android Shared Preferences?

The common location where SharedPreferences are stored in Android apps is: /data/data//shared_prefs/ User with root privileges can navigate to this location and can change its values.Need of protecting it is of much…
Harsh Dattani
  • 2,109
  • 1
  • 17
  • 27