When we save some small amount of data, especially some key,value this kind of data is saved in sharedpreferences, there are two ways to get Sharedpreferences on Android,
1: Acquired through context contexts, ctx.getsharedpreferences
2: Via Preferencemanager.getdefaultsharedpreferences (CTX)
But these two kinds of data to save the file name is not the same, the first file name is its own definition, the second is the system to write dead, is packagename+"_preferences.xml",
Now look at the source:
public static Sharedpreferences Getdefaultsharedpreferences (context context) {
Return Context.getsharedpreferences (Getdefaultsharedpreferencesname (context),
Getdefaultsharedpreferencesmode ());
}
Getdefaultsharedpreferencesname (context) method:
private static String Getdefaultsharedpreferencesname (context context) {
return Context.getpackagename () + "_preferences";
}
private static int Getdefaultsharedpreferencesmode () {
return context.mode_private;
}
This is the source code is simple, not much to say
Two ways to get Sharedpreference objects in Android