Store sharedpreference to Constant class and use static variables than set and get values from that class anytime you want.
Setting values in Preference:
MY_PREFS_NAME - a static String variable like:
public static final String MY_PREFS_NAME = "MyPrefsFile";
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString("name", "Amit");
editor.putInt("idName", 888);
editor.commit();
Retrieve data from preference:
SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
String restoredText = prefs.getString("text", null);
if (restoredText != null) {
String name = prefs.getString("name", "No name defined"); //"No name defined" is the default value.
int idName = prefs.getInt("idName", 0); //0 is the default value.
}
check this answer for more details.