如何在暂停android时保持搜索栏的状态?

发布于 2025-01-04 06:19:33 字数 246 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微凉 2025-01-11 06:19:33

您必须保存应用程序的状态,然后在应用程序再次启动时使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文