我目前有一个播放音乐的活动。 当活动被破坏(即用户旋转屏幕)时,我让应用程序存储音乐播放器的状态,然后在重新创建活动后从歌曲中的确切位置播放音乐。
我唯一的问题是,当重新创建活动时,音乐会有明显的停顿。 关于如何在更有效地重新创建应用程序方面提高活动性能的任何想法。 我知道我可以通过在android清单中使用configChanges标签来阻止活动不重新创建对象,但我想避免这种情况。
在单独的服务中运行音乐是我唯一的选择吗?
I currently have an activity that plays music. When the activity is destroyed (i.e. user rotates the screen) I have the application store the music player's state and then play the music from the exact spot in the song once the activity is re-created.
My only issue is that there is a noticeable pause in the music when the activity is re-created. Any ideas on how to increase the activity's performance in regards to re-creating the app more efficiently. I know I can stop the activity to not re-create objects by using the configChanges tag in the android manifest but I would like to avoid that.
Is running the music in a separate service my only option?
最满意答案
由于活动被破坏,无论你做什么,它都会暂停。 您应该为此目的使用服务。 服务在单独的线程上运行,不受您的活动影响。 有很多关于服务的教程和stackoverflow问题
Since the activity is destroyed it will pause no matter what you do. You should use a Service for this purpose. A service runs on a separate thread and is not effected by your activity. There's loads of tutorials and stackoverflow questions for services
更多推荐
发布评论