Hi guys I have recently come across a really weird problem that I cannot understand. I have tried a few work-arounds, but to no avail.
Basically as the title says, I am saving an ArrayList through the preferences but whenever I access the ArrayList it comes back shuffled.
I am drawing this to a ListView and if I have the ListView looking like:
1
2
3
4
5
6
It will come back looking like
3
2
1
6
5
4
This is my code for the onPause and on onResume
ArrayList<String> todoItems = new ArrayList<String>();
@Override
protected void onPause() {
// TODO Auto-generated method stub
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor edit = prefs.edit();
edit.putStringSet("TODOITEMS", new HashSet<String>(todoItems));
edit.commit();
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
ArrayList<String> returnedItems = new ArrayList<String>
(PreferenceManager.getDefaultSharedPreferences
(getBaseContext()).getStringSet("TODOITEMS",
new HashSet<String>()));
todoItems.clear();
for(int i =0; i < returnedItems.size(); i++){
todoItems.add(returnedItems.get(i));
}
aa.notifyDataSetChanged();
super.onResume();
}