如何保存“正在播放" Android中的Music Player App列表?

问题描述:

我将使用Service为Android创建一个简单的Musicplayer.

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.

这样浪费时间,有时数据库和Arraylist之间的数据难以同步.

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.

您可以使用对象数组列表来存储音乐播放器列表,并且需要使用 intent PUT方法将其通过活动通过.

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.

这是一个示例

intent.putStringArrayListExtra(数据",数据)

intent.putStringArrayListExtra("data", data)

这是您需要的代码的骨架:

Here is a skeleton of the code you need:

//创建列表 私人列表测试;

// Create the list private List test;

test = new ArrayList(); //将一些项目添加到列表中.

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

//调用PUT方法 Intent intent = getIntent(); intent.putStringArrayListExtra("test",(ArrayList)test);

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

然后您将像下面的代码一样进行检索.

And the you will retrieve like the code below.

ArrayList测试= data.getStringArrayListExtra(测试");

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

希望有帮助.