getDefaultSharedPreferences()
uses a default preference-file name like "com.example.something_preferences"
. This default is set per application, so all activities in the same app context can access it easily as in the following example:
SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(this);
if (spref.contains("email")) {
String sEmailAddr = spref.getString("email", "");
}
The preferences are usually stored at /data/data/com.package.name/shared_prefs/com.package.name_preferences.xml
getSharedPreference is the best way because using getDefaultSharedPreferences has some flaws
- Actualy
getDefaultSharedPreferences
doesn't work correct on some
devices when build with targer api 13
- Starting app from shortcut and from menu gives me different
DefaultSharedPreferences
. After removing DefaultSharedPreferences
from my code - it works perfect. I can't just say: people dont make
shrotcuts, so I had to change code
This link may also help