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


    }
  • 相关阅读:
    margin问题
    IE6里面子集尺寸大的会把父亲撑大
    第一个元素<flout>写了,想在他的旁边加一个元素.IE6会出现缝隙. 不要用margin撑开,要用flout
    兼容性,float
    HTML5的兼容问题以及调用js文件的方法
    表单
    表格的编写,课程表
    SmartThreadPool
    C# 多线程的等待所有线程结束的一个问题
    DataTable保存与读取 stream
  • 原文地址:https://www.cnblogs.com/la66/p/7883476.html
Copyright © 2011-2022 走看看