zoukankan      html  css  js  c++  java
  • SharedPreferences的简单使用

    package com.example.shishangyuan;

    import android.content.Context;
    import android.content.SharedPreferences;


    //存储类
    public class SharedUtils {
    //存账号的方法
    public static void setName(Context context,String name){
    //SharedPreferences存储类 1.参数 键 2.参数 值
    SharedPreferences sharedPreferences=context.getSharedPreferences("name",0);
    //写入Editor类 定义写入对象
    SharedPreferences.Editor editor=sharedPreferences.edit();
    //1参数 定义的标记 键 2参数 传的值 值
    editor.putString("name",name);
    // 提交
    editor.commit();

    }
    //取的方法
    public static String getName(Context context){
    SharedPreferences sharedPreferences=context.getSharedPreferences("name",0);
    //1参数 存的时候的一个键 2参数 取出来的值 ,默认值为“”; Null和“” 不一样的 “”一个占内存空间,null一个不占内存空间
    return sharedPreferences.getString("name","");
    }
    //存密码
    public static void setPwd(Context context,String pwd){
    //存储类
    SharedPreferences sharedPreferences=context.getSharedPreferences("pwd",0);
    //写入类
    SharedPreferences.Editor editor=sharedPreferences.edit();
    editor.putString("pwd",pwd);
    editor.commit();

    }
    //取的密码方法
    public static String getPwd(Context context){
    SharedPreferences sharedPreferences=context.getSharedPreferences("pwd",0);
    return sharedPreferences.getString("pwd","");
    }
    //返回Userid Token 加密用的 账号的钱 昵称 年龄 性别


    }
  • 相关阅读:
    easyui tree loader用法
    mysql字符集
    mysql 内连接 左连接 右连接 外连接
    mysql 聚集函数和分组
    mysql 大数据量求平均值
    C++ 纯虚方法
    Windows xcopy
    服务端数据库的操作如何不阻塞
    分布式系统业务服务器的设计
    mysql 查询执行的流程
  • 原文地址:https://www.cnblogs.com/la66/p/7883476.html
Copyright © 2011-2022 走看看