java - Saving and restoring an ArrayDeque onSaveInstanceState -
i working on video app thats uses arraydeque store our history of videos viewed, using push, pop. works i'm looking clean way of saving , restoring arraydeque
private deque<programmodel> mvideohistory = new arraydeque<>();
i save list saving arraylist.
@override public void onsaveinstancestate(final bundle outstate) { // save history arraylist<programmodel> history = new arraylist<>(); (programmodel program : mvideohistory) { history.add(program); } outstate.putparcelablearraylist("videohistory", history); }
then restore it
if (savedinstancestate != null) { // restore history arraylist<programmodel> history = savedinstancestate.getparcelablearraylist("videohistory"); mvideohistory = new arraydeque<>(history); }
can done in more efficient/cleaner way this?
ive tried outstate.putserializable("videohistory", mvideohistory.toarray());
restoring caused me problems.
you can this:
outstate.putserializable("videohistory", (arraydeque<programmodel>) mvideohistory);
cast again when restoring.
hope helps
Comments
Post a Comment