[英]What's the best way to store an id in local?
I'm coding an Android application. 我正在编写一个Android应用程序。 I need to store the id of a user in local in order that he doesn't have to rewrite its name, surname and password every time he uses the application. 我需要将用户的ID存储在本地,以便他不必在每次使用该应用程序时都重写其名称,姓氏和密码。 What is the best way to do this? 做这个的最好方式是什么?
You can use Shared Preferences to store id 您可以使用共享首选项存储ID
Code to save value 节省价值的代码
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();
Code to get value 获得价值的代码
String id = sharedpreferences.getString("id", "");
/*sharedpreferences.getString("key", "defaultValue"); */
There are 4 ways Some of the below methods are useful if you want to save more complex data. 有4种 方法如果要保存更复杂的数据,以下某些方法很有用。
Find the tutorial here 在这里找到教程
Check this tutorial to get through SQLite 查看本教程以了解SQLite
Find the tutorial here 在这里找到教程
my favorite- Documentation and HowToDo 我最喜欢的- 文档和HowToDo
little complex but fast- Documentation and HowToDo 有点复杂但是很快-文档和操作方法
Very good documentation and support over the internet- Documentation and How to do 互联网上非常好的文档和支持- 文档和操作方法
New but heavily used by tech giants- Documentation and how to do 新技术,但被技术巨头广泛使用- 文档以及操作方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.