Shared Preferences In View Page Indicator
I am using the viewpageIndicator Library in my application. I am using this sample class in my code. public class SampleTitlesWithListener extends BaseSampleActivity { @Overrid
Solution 1:
You could have a seperate class with static methods
Saving string in shared preferences and retrieve it again anywhere in your app.
publicclassPreferencesData {
publicstaticvoidsaveString(Context context, String key, String value) {
SharedPreferences sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(context);
sharedPrefs.edit().putString(key, value).commit();
}
publicstaticStringgetString(Context context, String key, String defaultValue) {
SharedPreferences sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(context);
return sharedPrefs.getString(key, defaultValue);
}
}
Usage example:
// save anywhere you have a context
PreferencesData.saveString(context, "mynote", "some note");
// retrieve anywhere you have a contextStringnote= PreferencesData.getString(context, "mynote", "defaultValue");
Post a Comment for "Shared Preferences In View Page Indicator"