I get certain data like say userName
in Activity_1
from a web server. Then i want to use the same data in Activity_2
so i made
As swayam suggested, i will suggest you yo go for a DB or Shared prefs, Especially Shared prefs suits best for your scenario;
You can use something like as follows:
To Put:
SharedPreferences sharedPreferences = getSharedPreferences("PREFS_READ",
Context.MODE_WORLD_READABLE);
Editor prefsPrivateEditor = sharedPreferences.edit();
prefsPrivateEditor.putString("yourkey", userName);
prefsPrivateEditor.commit();
To Get:
SharedPreferences sharedPreferences;
Context otherAppsContext = null;
try {
otherAppsContext = getApplication().createPackageContext(
"your.package.name", 0);
} catch (NameNotFoundException e) {
Toast.makeText(Email.this, e.toString(), Toast.LENGTH_LONG).show();
}
sharedPreferences = otherAppsContext.getSharedPreferences("PREFS_READ",
Context.MODE_WORLD_WRITEABLE);
String getusername = sharedPreferences.getString("yourkey","default_value");