Store Arraylist Using Shared Preferences
------------------------------------------------------
SharedPreferences prefs=this.getSharedPreferences("yourPrefsKey",Context.MODE_PRIVATE);
Editor edit=prefs.edit();
Set<String> set = new HashSet<String>();
set.addAll(your Arraylist Name);
edit.putStringSet("yourKey", set);
edit.commit();
Retrieve Arraylist from Shared Preferences
-----------------------------------------------------
Set<String> set = prefs.getStringSet("yourKey", null);
List<String> sample=new ArrayList<String>(set);
------------------------------------------------------
SharedPreferences prefs=this.getSharedPreferences("yourPrefsKey",Context.MODE_PRIVATE);
Editor edit=prefs.edit();
Set<String> set = new HashSet<String>();
set.addAll(your Arraylist Name);
edit.putStringSet("yourKey", set);
edit.commit();
Retrieve Arraylist from Shared Preferences
-----------------------------------------------------
Set<String> set = prefs.getStringSet("yourKey", null);
List<String> sample=new ArrayList<String>(set);
perfect answer. Its really helpful.
ReplyDeleteeasy answer nice tutorial
ReplyDeleteCan you provide the entire code.
ReplyDeleteWhere we have to add these line in on create or we have to create separate method
thanks a lot
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHow can i store and retrieve ArrayList of LatLng (or any kind of object) to sharedpreferences?
ReplyDeleteHow do i iterate through the list containing the items?
ReplyDeleteThere is no method putIntSet("yourKey", set);
ReplyDeleteIs there alternative for this?
Attempt to invoke interface method 'java.util.Set android.content.SharedPreferences.getStringSet(java.lang.String, java.util.Set)' on a null object reference
ReplyDelete