问题
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