1

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.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Robomini
  • 11
  • 3

1 Answers1

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.

  • this solution just send data between Activity and Service. If you stop this app and start again, data will be lost. But nowplaying list must be saved between difference running of App. – Robomini Sep 01 '12 at 14:54