如何在暂停android时保持搜索栏的状态?
android 开发人员
我有一个使用媒体播放器从 SD 卡播放音乐的应用程序。 在此应用程序中,我有一个搜索栏来指示正在播放的音乐。 搜索栏在线程中运行,并在播放音乐时更新。
如果按后退按钮,音乐仍然按我想要的方式播放。 但如果我再次单击该应用程序,搜索栏又回到 0。 这意味着所有实例都是新创建的。
当我按下后退按钮时,我应该做什么来保存媒体播放器的实例? 我应该在 onPause 和 onResume 上执行什么样的实现?
android developer
I have an application that play music from sd card using media player.
In this application, I have a seekbar to indicate the music that being play.
The seekbar run in thread, and updated while music is playing.
If a press the back button, the music is still playing as I want.
But if I click the application again, the seekbar is back to 0.
It means all instances are created the new one.
What I supposed to do, to save the instance of the media player when I press back button?
What kind of implementation that I should do at onPause and onResume?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须保存应用程序的状态,然后在应用程序再次启动时使用
onRestoreInstanceState
恢复它。请参阅此处使用“保存实例状态”保存 Android Activity 状态you have to save the state of your application and then restore it using
onRestoreInstanceState
when your application start again. see here Saving Android Activity state using Save Instance State