Android背景音乐服务重启(Android background music service restart)

编程入门 行业动态 更新时间:2024-10-25 14:28:50
Android背景音乐服务重启(Android background music service restart)

我的应用程序使用服务控制类扩展应用程序中的音乐。 应用程序启动时调用后台音乐服务。 并覆盖onUserLeaveHint()以停止服务。

为了防止音乐在各种活动中停止,我添加了旗帜

intent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);

所以音乐没有停止,它运作正常。 但问题是主页按钮。

当我按下主页按钮时,音乐停止了。 然后我打开应用程序音乐仍然停止。 因为没有调用启动服务,只有应用程序onCreate。

这就是我想重启服务的原因。 如何查看已启动或已停止的服务?

感谢您阅读此问题!

My application control music in class extents application using service. Background music service called when application starts. And Overriding onUserLeaveHint() to stop service.

To prevent music stop across activities, I added flag

intent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);

So Music isn't stopped and it works fine. But problem is home button.

When I push home button, music stopped. And then I open application music still stopped. Because there are no call for start service, only except application onCreate.

That's why I want to restart service. How can I check service started or stopped?

Thanks for read this question!

最满意答案

尝试在onResume或onStart方法上启动服务。

Try to start the service on onResume or on onStart method.

更多推荐

本文发布于:2023-08-05 10:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1431234.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重启   背景音乐   Android   background   restart

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!