How to share same data between multiple activities

Use shared preferences like this:

SharedPreferences myprefs= this.getSharedPreferences("user", MODE_WORLD_READABLE);
myprefs.edit().putString("session_id", value).commit();

You can retrieve this info across your app like this:

SharedPreferences myprefs= getSharedPreferences("user", MODE_WORLD_READABLE);
String session_id= myprefs.getString("session_id", null);

You should use intents when you want to start another activity from your current activity… also if the child activity is totally dependent on data from parent activity …use intents

Leave a Comment