我的应用程序使用服务控制类扩展应用程序中的音乐。 应用程序启动时调用后台音乐服务。 并覆盖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.
更多推荐
发布评论