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 加密用的 账号的钱 昵称 年龄 性别


    }
  • 相关阅读:
    kafka 学习笔记
    awk命令详解
    apache 的 配置项
    Apache 的 httpd.conf 详解
    如何设置httpd-mpm-conf的参数
    apache 服务器概述--安装(一)
    centos 修改时区
    docker(三)docker镜像和镜像发布方法
    docker(二)部署docker容器虚拟化平台
    sql的存储过程使用详解--基本语法
  • 原文地址:https://www.cnblogs.com/la66/p/7883476.html
Copyright © 2011-2022 走看看