zoukankan      html  css  js  c++  java
  • SharedPreferences(共享参数)

    //共享参数,多用于自动登录,是 android常用的数据储存的一种,用于储存少量数据,Integer,Double,String等。

    public class sharp {
        Context context;                 //接收上下文对象
    
        public sharp(Context context) { //构造函数
            this.context = context;
        }
    //存储数据
        public void read(User user){
            SharedPreferences pre=context.getSharedPreferences("pp",Context.MODE_PRIVATE);          //“pp”为共享文件名
            SharedPreferences.Editor editor=pre.edit();//创建Editor
            editor.putString("id",user.getId());        //把用户名刺入到共享文件里
            editor.putString("pwd",user.getPwd());
            editor.putString("qx",user.getQx());
            editor.commit();
        }
    //读取数据
    public User write(){ SharedPreferences shp=context.getSharedPreferences("pp",Context.MODE_PRIVATE); String id=shp.getString("name","no");//“no”为默认值 String pwd=shp.getString("pwd","no"); String qx=shp.getString("qx","no"); User user=new User(id,pwd,qx); return user; } }
  • 相关阅读:
    bfs两种记录路径方法
    次小生成树
    2018 ICPC 区域赛 焦作场 D. Keiichi Tsuchiya the Drift King(计算几何)
    数组分组
    POJ
    数位DP详解
    2018ICPC青岛 E
    HDU
    Google工程师打造Remix OS系统 桌面版安卓下载
    使用angular封装echarts
  • 原文地址:https://www.cnblogs.com/Xacm/p/5500518.html
Copyright © 2011-2022 走看看