Reputation: 123
I am trying to create a list of certaing objects, so i can see it anytime and anywhere. So i was wondering if there is any way to have some information in an Android activity, and sees it in the other activities just like the Session[] in asp.net.
Upvotes: 1
Views: 800
Reputation: 6591
Check out the Android Application
class. It's essentially a singleton with the lifetime of your app.
Or as others have suggested, use Shared Preferences to a) persist things across Activities
and b) persist things across "sessions".
Upvotes: 2
Reputation: 46
You can use Android Shared Preferences
SharedPreferences prefs = getSharedPreferences("myPreferences",Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("email", "[email protected]");
editor.putString("name", "Test");
editor.commit();
And to get the data use this:
SharedPreferences prefs =
getSharedPreferences("myPreferences",Context.MODE_PRIVATE);
String email= prefs.getString("email", "[email protected]");
Upvotes: 3
Reputation: 15052
This or simple Shared Preferences might be what you are looking for.
Upvotes: 1
Reputation: 1639
You can push all your shared information in a static object.
The best way to do it is to create a singleton. Here is a sample: http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html
Upvotes: 0