我有一个音乐播放器,试图启动其中Service
的onResume()
一个Activity
。为了清楚起见,我删除了几行,但是代码有效:
@Override
protected void onResume() {
super.onResume();
startService(new Intent(this, MusicService.class));
}
根据崩溃日志,这在某些运行Android P的设备上引发异常:
Caused by java.lang.IllegalStateException: Not allowed to start service Intent { cmp=another.music.player/com.simplecity.amp_library.playback.MusicService }: app is in background uid UidRecord{6a4a9c6 u0a143 TPSL bg:+3m25s199ms idle change:cached procs:1 seq(1283,1283,1283)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1577)
at android.app.ContextImpl.startService(ContextImpl.java:1532)
at android.content.ContextWrapper.startService(ContextWrapper.java:664)
at android.content.ContextWrapper.startService(ContextWrapper.java:664)
at com.simplecity.amp_library.utils.MusicServiceConnectionUtils.bindToService(SourceFile:36)
at com.simplecity.amp_library.ui.activities.BaseActivity.bindService(SourceFile:129)
at com.simplecity.amp_library.ui.activities.BaseActivity.onResume(SourceFile:96)
在onResume()
(和super.onResume()
)调用之后,我的应用程序怎么可能在后台?
这对我来说毫无意义。这可能是平台错误吗?受此崩溃影响的所有3500+用户都在Android P上。