android - Simple way to store a Linked List -
hi working on android application, , need store linkedlist when user terminated app app processes. have looked @ question easy way save linkedlist in android application?
and accepted answer doesn't seem work , androidstudio complains expects , array list rather linked list. realise question 3 years old , must have changed in time not work.
can linked lists stored in bundle anymore? or have better way of making linkedlist persistant?
cheers
as mentioned in comment, won't able save linkedlist
bundle, can, however, convert linkedlist
arraylist
save it, convert when load application again. constructor arraylist
, linkedlist
accept collection
, add elements in order iterator returns them (i.e. fifo linkedlist)
public void onsaveinstancestate(bundle outstate) { super.onsaveinstancestate(outstate); arraylist<myobject> listtosave = new arraylist<myobject>(mylinkedlist); outstate.putparcelablearraylist("key", listtosave); } public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if (savedinstancestate != null) { arraylist<myobject> loadedlist = savedinstancestate.getparcelablearraylist("key"); mylinkedlist = new linkedlist<myobject>(loadedlist); } }
Comments
Post a Comment