How to save “now playing” list of Music Player App in Android?

可紊 提交于 2019-12-11 05:35:59

问题


I'm going to create a simple Musicplayer for Android using Service.

But I don't know the best way to save list of nowplaying.

I used a database to store the list, but in this way, each time I start main player activity, I must read database and store to an array list and each time I update nowplaying, I must update the database.

This way make waste of time and sometime data between Database and Arraylist is difficult to synchonized.

What's the best way to solve this problem? - Store nowplaying list of musicplayer app and app must be run fast enough.


回答1:


You could use a Object Array List to store the music player list and you need to pass it trough activities using the intent PUT method.

here is an example

intent.putStringArrayListExtra("data", data)

Here is a skeleton of the code you need:

// Create the list private List test;

test = new ArrayList(); //Add some items to the list.

// Call the PUT method Intent intent = getIntent(); intent.putStringArrayListExtra("test", (ArrayList) test);

And the you will retrieve like the code below.

ArrayList test = data.getStringArrayListExtra("test");

Hope that helps.



来源:https://stackoverflow.com/questions/12216587/how-to-save-now-playing-list-of-music-player-app-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!