保持用户状态的Andr​​oid [英] Keep user state in Android

查看:131
本文介绍了保持用户状态的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序,需要得到具体的信息为每个用户。

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

我在使用GET和POST方法的认证。现在我已经通过时的用户名和密码是正确的服务器发送的cookie

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.

我如何存储这些数据?我找了,但没有找到存储在Android的会话的最佳途径。

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

如何应用,如四方,Facebook的例如保持一个用户的状态?他们如何保持数据?

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

推荐答案

如果您只想存储一些用户信息,您可以使用共享preferences只要你可以从服务器获取文本。

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();

在您复制从服务器到共享preferences的信息,您可以访问它像这样:

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

data = prefs.getString("field_name");

这篇关于保持用户状态的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆