码迷,mamicode.com
首页 > 编程语言 > 详细

SharedPreferences 存储数组

时间:2015-03-06 12:27:50      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

public static void saveApkEnalbleArray(Context context,boolean[] booleanArray) {
SharedPreferences prefs = context.getSharedPreferences(APK_ENABLE_ARRAY, Context.MODE_PRIVATE);
JSONArray jsonArray = new JSONArray();
for (boolean b : booleanArray) {
jsonArray.put(b);
}
SharedPreferences.Editor editor = prefs.edit();
editor.putString(APK_ENABLE_ARRAY,jsonArray.toString());
editor.commit();
}
public static boolean[] getApkEnableArray(Context context,int arrayLength)
{
SharedPreferences prefs = context.getSharedPreferences(APK_ENABLE_ARRAY, Context.MODE_PRIVATE);
boolean[] resArray=new boolean[arrayLength];
Arrays.fill(resArray, true);
try {
JSONArray jsonArray = new JSONArray(prefs.getString(APK_ENABLE_ARRAY, "[]"));
for (int i = 0; i < jsonArray.length(); i++) {
resArray[i] = jsonArray.getBoolean(i);
}
} catch (Exception e) {
e.printStackTrace();
}

return resArray;
}

SharedPreferences 存储数组

标签:

原文地址:http://www.cnblogs.com/manmanlu/p/4317704.html

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