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;
}
SharedPreferences mPrefs = getSharedPreferences("label", 0);
String mString = mPrefs.getString("tag", "default_value_if_variable_not_found");
SharedPreferences.Editor mEditor = mPrefs.edit();
mEditor.putString("tag", value_of_variable).commit();
SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putInt("your_int_key", yourIntValue);
editor.commit();