I am trying to store user id in SharedPreference in one activity and want to get this integer id in any activity.
To put this value in Shared Preference i use following code.
SharedPreferences myPrefs = getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
SharedPreferences.Editor prefsEditor = myPrefs.edit();
prefsEditor.putInt("userId", varaible);
prefsEditor.commit();
Then i am trying to get this value, i use following code for this
SharedPreferences myPrefs = getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
int userId = myPrefs.getInt("userId", -1);
But it return me -1 not userId. and if i use following line to fetch integer value then it will showing runtime exception.
int userId = myPrefs.getInt("userId", Integer(null));
I don't understand what's wrong in my code. How to get this integer userId in my another activity.
Please give me any reference or hint.
Thanks in advance.