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;
        }
    
    }
  • 相关阅读:
    UVA 439 Knight Moves
    UVA 673 Parentheses Balance
    UVa 536 Tree Recovery
    UVA 712 S-Trees
    UVA 12657 Boxes in a Line
    UVA 679 Dropping Balls
    UVA 1603 Square Destroyer
    UVA 1343 The Rotation Game
    UVA 1374 Power Calculus
    UVA 12558 Egyptian Fractions (HARD version)
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/10314290.html
Copyright © 2011-2022 走看看