如何保存“正在播放"Android 中的音乐播放器应用程序列表? [英] How to save "now playing" list of Music Player App in Android?

查看:28
本文介绍了如何保存“正在播放"Android 中的音乐播放器应用程序列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用服务为 Android 创建一个简单的音乐播放器.

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.

我使用了一个数据库来存储列表,但是这样,每次我开始主玩家活动时,我必须读取数据库并存储到一个数组列表中,每次更新 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.

这种方式浪费时间,有时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("data", data)

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方法意图意图 = 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 test = data.getStringArrayListExtra("test");

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

希望有所帮助.

这篇关于如何保存“正在播放"Android 中的音乐播放器应用程序列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆