Static Sharedpreferences
I have two methods in an activity private void save(String tag, final boolean isChecked) { SharedPreferences sharedPreferences = getPreferences(Context.MODE_PRIVATE); Share
Solution 1:
You could save and load from Application
-wide shared preferences instead of prefs private to the Activity
:
privatestaticbooleanload(String tag) {
SharedPreferences sharedPreferences = Context.getApplicationContext().getSharedPreferences("namespace", Context.MODE_PRIVATE);
return sharedPreferences.getBoolean(tag, false);
}
If you do this, make sure you are also storing the preferences in the same way (by using Context.getApplicationContext().getSharedPreferences
)
Post a Comment for "Static Sharedpreferences"