Can we use preferences accress multiple different acvtivities in android?
Posted
by Maneesh
on Stack Overflow
See other posts from Stack Overflow
or by Maneesh
Published on 2010-06-05T11:47:57Z
Indexed on
2010/06/05
11:52 UTC
Read the original article
Hit count: 203
android
|android-emulator
I save preferences in one activities but not able to get saved preferences in other activity. I can access saved preferences in the same activity but not in other one. It is not giving me any error but always gibing null values in second activity.
Below is the code:
First Activity:
SharedPreferences.Editor editor;
editor.putString("token", access_token);
editor.commit();
Second Activity:
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);//getPreferences(0);
String restoredtoken = prefs.getString("token", null);
if (restoredtoken== null) {
///doing some task;
}
© Stack Overflow or respective owner