views:

49

answers:

2

I am developing an Android app that needs to receive specific informations for each user.

I made an authentication using GET and POST methods. Now I have the cookie delivered by the server when the username and password are correct.

How do I store this data? I looked for but couldn't find the best way to store a session in Android.

How applications like Foursquare, Facebook for example keep the state of an user? How do they persist data?

+1  A: 

Those apps most likely use the AccountManager to store account data. In your case it may be easier for you to just store the user's login information into SharedPreferences that you can recall when the Activity starts.

BrennaSoft
+1  A: 

If you just want to store some user info, you can use SharedPreferences as long as you can get the text from the server.

Once you have the text you want to save:

final SharedPreferences prefs = context.getSharedPreferences();
Editor editor = prefs.edit();
editor.putString("field_name", data);
editor.commit();

Once you copy the info from the server to the SharedPreferences, you can access it like so:

data = prefs.getString("field_name");
sirconnorstack

related questions