java - Android:how to store and retrieve Hashmap data in sharedpreferences? -


i want store data key , value pair in internal storage. using hashmap store key,value pair .but don'get sufficient solution store , retrieve hashmap sharedpreferences. please give me solution.

i put code below:

hashmap<string, string> maplistmesasges = new hashmap<string, string>(); maplistmesasges.put(fromname, message.getbody()); preferences = mactivity.getsharedpreferences(                                 sharepreference_messages_history_name,                                 context.mode_private);                         sharedpreferences.editor editor = preferences.edit();                         (entry<string, string> entry : maplistmesasges                                 .entryset()) {                             editor.putstring(entry.getkey(), entry.getvalue());                         }                         editor.commit(); 

and retrieve data sharedprefernces:

preferences = mactivity.getsharedpreferences(                 sharepreference_messages_history_name, context.mode_private);         (entry<string, ?> entry : preferences.getall().entryset()) {             maplistmesasges.put(entry.getkey(), entry.getvalue().tostring());         } 

i store hashmap in adapter , set listview. main purpose store , retrieve data sharedprefernces , show data listview.

thanks in advance.

the easiest way store hashmap in preferences convert string , store it.

on otherside string convert in hashmap , enjoy.

to convert string hashmap & vice-versa check this link.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -