I want to store hashmap to my android application that when restart ,it shows last saved values of hashmap.
HashMap HtKpi=new HashMap&l
Serialize it and save it in shared preferences or in a file. Whether you can do this, of course, depends on the data types being mapped from and to. (This won't work, for instance, if you try to serialize a View.)
Example:
//persist
HashMap counters; //the hashmap you want to save
SharedPreferences pref = getContext().getSharedPreferences("Your_Shared_Prefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
for (String s : counters.keySet()) {
editor.putInteger(s, counters.get(s));
}
editor.commit();
//load
SharedPreferences pref = getContext().getSharedPreferences("Your_Shared_Prefs", Context.MODE_PRIVATE);
HashMap map= (HashMap) pref.getAll();
for (String s : map.keySet()) {
Integer value=map.get(s);
//Use Value
}