android java sharedpreferences example
Example: android save int
public void saveInt(int val, String key){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(key, val);
editor.apply();
}
public int getInt(String key){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity);
int val = prefs.getInt(key, 0);
return val;
}