我有一个音乐播放器,它试图启动一个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()
(and ) 之后立即在后台运行?super.onResume()
这对我来说没有任何意义。这可能是平台错误吗?受此崩溃影响的所有 3500 多名用户都使用 Android P。