• 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;
        }
    
    }
  • 相关阅读:
    python基础
    HTTP长连接和短连接及应用情景
    HTTP和HTTPS的区别
    python---重建二叉树
    python---替换空格
    python---二维数组的查找
    python---从尾到头打印链表
    python---反转链表
    python---两个栈实现一个队列
    python---二分查找的实现
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/10314290.html
Copyright © 2020-2023  润新知