【发布时间】:2014-06-09 07:17:42
【问题描述】:
i am developing an android app where i have to save dates (* as given in array)
i am doing this by using shared preferences
my code is working fine but it do some different behaviour which i dont know why
a.> when i am saving array in shared prefrences it works perfect as i want but
b.> when it comes to fetching data it keeps single date if the date occurs twice in array ex.. 24 occurs 2 times in my array but on fetching it show me single 24
c.> also it gives me unordered representation of array
i dont know why this is happening and how to solve it
**some one told me to use serialize but i dont know how to do this? **
String[][] my_date;
my_date = new String[][] {
{"14","26"},
{"12","16","24","27"},
{"17"},
{"8","13","18"},
{"14"},
{},
{"29"},
{"15","18"},
{},
{"2","3","6","8","23"},
{"4","6","24"},
{}
};
/* storing the data in shared preferences */
SharedPreferences pref = arg0.getSharedPreferences("MyPref", 0); // 0 - for private mode
SharedPreferences.Editor editor = pref.edit();
Set<String> set = new HashSet<String>();
for(int i=0; i<my_date.length;i++){
for(int j =0; j<my_date[i].length;j++){
set.add("'"+my_date[i][j]+"'");
Log.v("dates",my_date[i][j]);
}
}
editor.putStringSet("dates", set);
editor.commit();
/* fetching saved data */
set=pref.getStringSet("dates", set);
Log.v("dates",set+"----"+set.size());
【问题讨论】:
标签: android serialization sharedpreferences