Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read SharedPreferences when you haven't set the name of the file

When you createa a PreferenceScreen on Android, your application creates a default SharedPreferences file for the settings. I want to read this name, or get a reference without specifing the name.

Currently I use:

SharedPreferences prefs = ctx.getSharedPreferences("prefs", 0);
SharedPreferences.Editor ed=prefs.edit();

But this returns another copy of the preference. When I checked the folder in /data/data/myapk/shared_prefs

I see two files, one named prefs.xml and the other is my [package name]_preferences.xml (this was created by the PreferenceActivity);

How do I get an instance of the shared preference with the usage of the default file name, so I should not mention a name for it?

like image 270
Pentium10 Avatar asked Mar 08 '10 17:03

Pentium10


1 Answers

I'm fairly sure you want PreferenceManager.getDefaultSharedPreferences(Context context).

like image 148
Dan Lew Avatar answered Oct 19 '22 10:10

Dan Lew