zoukankan      html  css  js  c++  java
  • Android 开发 SharedPreferences数据会话类模板

    简单的模板

      

    public class SPDataSession {
        private static SPDataSession mSPDataSession;
        private SharedPreferences.Editor mEditor;
        private SharedPreferences mSP;
        private SPDataSession(){
            mEditor = App.context().getSharedPreferences("data",Context.MODE_PRIVATE).edit();
            mSP = App.context().getSharedPreferences("data",Context.MODE_PRIVATE);
    
        }
        public static SPDataSession I(){
            if (mSPDataSession == null){
                mSPDataSession = new SPDataSession();
            }
            return mSPDataSession;
        }
    
        /**
         * 保存第一次登入
         */
        public void saveFirst(){
            mEditor.putBoolean("first",true);
            mEditor.apply();
        }
    
        /**
         * 获取第一次登入记录
         * @return
         */
        public boolean getFirst(){
            return mSP.getBoolean("first",false);
        }
    
        /**
         * 保存设备识别id
         * @param deviceId
         */
        public void saveDeviceId(String deviceId){
            mEditor.putString("deviceId",deviceId);
            mEditor.apply();
        }
    
        /**
         * 获取设备识别id
         * @return
         */
        public String getDeviceId(){
            return mSP.getString("deviceId","");
    
        }
    
        /**
         * 判断token为空
         * @return true=空 false=不为空
         */
        public boolean isTokenEmpty(){
            if (TextUtils.isEmpty(mSP.getString("token",""))){
                return true;
            }
            return false;
        }
    
    }
  • 相关阅读:
    在windwos创建的脚本文件在linux环境中无法执行的问题
    shell的文件锁操作
    systemd target
    算法-排序数组
    算法-存在重复元素
    算法-移除元素
    算法-两数之和
    touch事件详解
    小程序 打包太大
    taro/vue 左滑删除购物车
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/10314290.html
Copyright © 2011-2022 走看看