sharedpreferences - how can i store my player's Playlist in Android programmatically -


i building music player , want store playlist after app closed , retrieve when app started. able playlist in array list. please help..

to save when app closed override onpause method inside activity or fragment save playlist arraylist maybe in sqlite database, file or sharedpreference. retrieve write code in oncreate method can retrieve saved data.

i didn't deal sqlite here sharedpreference code if wanna

class playlist {     private final string filename = "myplaylist";     private sharedpreferences myplaylist;     private sharedpreferences.editor myeditor;      playlist() {         myplaylist = getsharedpreferences(filename, 0);         myeditor = myplaylist.edit();     }      public void save(arraylist<string> mysongs){         // save size can retrieve whole list later         myeditor.putint("listsize", mysongs.size());          for(int = 0; < mysongs.size(); i++){             // save each song index in list key             myeditor.putstring(string.valueof(i), mysongs.get(i));         }          myeditor.commit();     }     public arraylist<string> load() {         // create new array returned         arraylist<string> savedsongs = new arraylist<string>();          // number of saved songs         int numofsavedsongs = myplaylist.getint("listsize", 0);          // saved songs index         (int = 0; < numofsavedsongs; i++) {             savedsongs.add(myplaylist.getstring(string.valueof(i)));         }          return savedsongs;     } } 

sorry if code contains mistakes didn't test it. hope helps


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -