android键值对
来源:互联网 发布:python.pdf 编辑:程序博客网 时间:2024/05/17 06:10
/** * 键值对写工具 */package xx.utils;import java.io.IOException;import java.util.Map;import java.util.Map.Entry;import android.app.Activity;import android.content.Context;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;public class EditKeyValueUtils { /** * 将对象base64编码之后写入默认文件的指定的键 * @param context * @param object 对象 * @param key 指定键 * @return */ public boolean editObjectToLocal(Context context,Object object,String key){ return editObjectToLocal("application", context, object, key); } /** * * 将对象base64编码之后写入制定的键 * * @param filePath 写入的文件名称 * @param context * @param object 对象 * @param key 指定键 * @return */ public boolean editObjectToLocal(String filePath,Context context,Object object,String key){ try { String objectStr = new Base64Utils().encodetoBase64(object); SharedPreferences preferences=context.getSharedPreferences(filePath, Activity.MODE_PRIVATE); Editor editor=preferences.edit(); editor.putString(key, objectStr); editor.commit(); return true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } } /** * 从默认文件中取得指定键的值 * @param context * @param key * @return */ public Object getObjectFromLocal(Context context,String key){ return getObjectFromLocal("application", context, key); } /** * 从文件中取得指定键的值 * @param filePath * @param context * @param key * @return */ public Object getObjectFromLocal(String filePath,Context context,String key){ try { SharedPreferences preferences=context.getSharedPreferences(filePath, Activity.MODE_PRIVATE); String value=preferences.getString(key, ""); return new Base64Utils().decodeFromBase64(value); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } /** * 清空默认文件键值对 * @param context */ public void clearObjectLocal(Context context){ clearObjectLocal("application", context); } /** * 清空文件键值对 * @param filePath * @param context */ public void clearObjectLocal(String filePath,Context context){ SharedPreferences preferences=context.getSharedPreferences(filePath, Context.MODE_PRIVATE); Editor editor = preferences.edit(); Map<String, ?> map = preferences.getAll(); for(Entry<String, ?> set:map.entrySet()){ editor.remove(set.getKey()); } editor.commit(); } /** * 移除键值对 * @param context * @param key */ public void removeObjectLocal(Context context,String key){ removeObjectLocal("application", context,key); } /** * 移除指定文件键值对 * @param filePath * @param context * @param key */ public void removeObjectLocal(String filePath,Context context,String key){ SharedPreferences preferences=context.getSharedPreferences(filePath, Context.MODE_PRIVATE); Editor editor = preferences.edit(); editor.remove(key); editor.commit(); }}
0 0
- android键值对
- android键值对保存
- android中的键值对
- android 下拉列表 键值对
- android保存键值对数据
- Android SharedPreference存储键值对
- Android 之 Spinner 键值对的绑定
- Android 之 Spinner 键值对的绑定
- Android 之 Spinner 键值对的绑定
- Android 之 Spinner 键值对的绑定
- android Bundle类(键值对)
- Android Spinner控件之键值对用法
- Android 之 Spinner 键值对的绑定
- Android使用OkHttp post 键值对
- Android Spinner控件之键值对用法
- Swift-->NSUserDefaults键值对,Android中的SharedPreferences
- 键值对
- Android键值对保存成XML文件SharedPreferences
- 最小二乘拟合,L1、L2正则化约束
- final finally finalized区别
- linux之----------epoll函数
- 更改html北京图片大小
- 浅读《解密社群粉丝经济学》几点观点
- android键值对
- WebForms UnobtrusiveValidationMode 需要“jquery”ScriptResourceMapping
- Java解压缩技术(三)BZIP2压缩-解压缩
- Mac&iOS之多线程
- Android通信方式(三)-----WebService (Ksoap2实现)
- 银坐标:知识就是金钱
- apk反编译工具:apktool
- You are using safe update mode and you tried to update a table without a WHERE that uses a KEY colum
- sql server 查询一个表中的字段是否包含在另一个表的字段中