1public void saveInt(int val, String key){
2 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity);
3 SharedPreferences.Editor editor = prefs.edit();
4 editor.putInt(key, val);
5 editor.apply();
6}
7
8public int getInt(String key){
9 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity);
10 int val = prefs.getInt(key, 0);
11 return val;
12}