我有一个音乐播放器,它试图在Activity
的onResume()
中启动一个Service
。出于简洁起见,我删除了一些行,但代码实际上是:
@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上。