in Android why we have - Context.getSharedPreferences() and -Activity.getPreferences() but we can change the model in each one between private and multiple so it will be same !! i know there is another function but what is it ?
Asked
Active
Viewed 176 times
1 Answers
1
Always useful to read the documentation first! Furthermore reading the source code really helps a lot at times.
- Context.getSharedPreferences(String name, int mode)
This is the main method. What it does is it fetches the contents of preference file "name", stores and returns it via a singleton. - Activity.getPreferences(int mode)
As said, this just calls the above, but with specific name which actually is equal to:getLocalClassName()
- PreferenceManager.getDefaultSharedPreferences(Context)
This also calls Number 1 with the name:getPackageName() + "_preferences";
That said you can also supply the first two methods with ones of these modes:
- MODE_PRIVATE
The default mode you should be using (also default for Number 3). - MODE_MULTI_PROCESS
Meant to be used if your application has multiple processes, where a singleton is not enough to keep the preferences up-to-date. MODE_WORLD_READABLEDeprecated in API 17MODE_WORLD_WRITEABLEDeprecated in API 17

Simas
- 43,548
- 10
- 88
- 116