How to Intialize?
// 0 - for private mode`
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0);
Editor editor = pref.edit();
How to Store Data In Shared Preference?
editor.putString("key_name", "string value"); // Storing string
OR
editor.putInt("key_name", "int value"); //Storing integer
And don't forget to apply :
editor.apply();
How to retrieve Data From Shared Preferences ?
pref.getString("key_name", null); // getting String
pref.getInt("key_name", 0); // getting Integer