【发布时间】:2017-05-05 10:59:35
【问题描述】:
我正在编写一个 Android 应用程序。我需要将用户的 id 存储在本地,以便他不必在每次使用应用程序时重写其名称、姓氏和密码。 做这个的最好方式是什么?
【问题讨论】:
-
共享偏好
-
使用
SharedPreferences -
谢谢,我会搜索一些关于这个的文档
我正在编写一个 Android 应用程序。我需要将用户的 id 存储在本地,以便他不必在每次使用应用程序时重写其名称、姓氏和密码。 做这个的最好方式是什么?
【问题讨论】:
SharedPreferences
您可以使用共享偏好;
查看this教程。
【讨论】:
您可以使用 Shared Preferences 来存储 id
保存价值的代码
public static final String MyPREFERENCES = "MyPrefs" ;
SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("id", 1);
/*editor.putString("Key", value); */
editor.commit();
获取价值的代码
String id = sharedpreferences.getString("id", "");
/*sharedpreferences.getString("key", "defaultValue"); */
【讨论】:
有 4 种方法 如果您想保存更复杂的数据,以下一些方法很有用。
Check this tutorial to get through SQLite
我最喜欢的-Documentation and HowToDo
简单但快速-Documentation and HowToDo
非常好的文档和互联网支持-Documentation and How to do
新的但被科技巨头大量使用-Documentation and how to do
【讨论】: