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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -