在本地存储ID的最佳方法是什么? [英] What's the best way to store an id in local?

查看:98
本文介绍了在本地存储ID的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Android应用程序.我需要将用户的ID存储在本地,以便他不必在每次使用该应用程序时都重写其名称,姓氏和密码. 做这个的最好方式是什么?

I'm coding an Android application. 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. What is the best way to do this?

推荐答案

您可以使用共享首选项"存储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"); */

这篇关于在本地存储ID的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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