且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

保持用户状态的Andr​​oid

更新时间:2023-02-02 19:30:44

如果您只想存储一些用户信息,您可以使用共享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");