码迷,mamicode.com
首页 > 其他好文 > 详细

SPUtils

时间:2017-02-23 19:51:38      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:tor   log   share   get   ext.get   and   this   pen   instance   

package cn.itcast.demo;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import java.util.Map;

public class SPUtils {
   private Context context;
   private SharedPreferences sp;
   private Editor editor;

   public SPUtil(Context context) {
      this.context = context;
      sp = this.context.getSharedPreferences("config", Context.MODE_APPEND);
      editor = sp.edit();
   }

   public void getInstance(Context context, String filename) {
      this.context = context;
      sp = context.getSharedPreferences(filename, Context.MODE_APPEND);
      editor = sp.edit();
   }

   public void putBoolean(String key, Boolean value) {
      editor.putBoolean(key, value);
      editor.commit();
   }

   public boolean getBoolean(String key, Boolean defValue) {
      return sp.getBoolean(key, defValue);
   }

   public void putString(String key, String value) {
      if (key == null) {
         return;
      }
      editor.putString(key, value);
      editor.commit();
   }

   public String getString(String key, String defValue) {
      return sp.getString(key, defValue);
   }

   public void putInt(String key, int value) {
      editor.putInt(key, value);
      editor.commit();
   }

   public int getInt(String key, int defValue) {
      return sp.getInt(key, defValue);
   }

   public Map<String, ?> getAll() {
      return sp.getAll();
   }
}

 

SPUtils

标签:tor   log   share   get   ext.get   and   this   pen   instance   

原文地址:http://www.cnblogs.com/loaderman/p/6435097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!