android.app.BackgroundServiceStartNotAllowedException
--------- beginning of crash 05-09 01:25:24.465 2187 2187 E AndroidRuntime: FATAL EXCEPTION: main 05-09 01:25:24.465 2187 2187 E AndroidRuntime: Process: com.android.gallery3d, PID: 2187 05-09 01:25:24.465 2187 2187 E AndroidRuntime: java.lang.RuntimeException: Unable to start receiver com.android.gallery3d.app.PackagesMonitor: android.app.BackgroundServiceStartNotAllowedException: Not allowed to start service Intent { act=android.intent.action.PACKAGE_CHANGED dat=package:com.mycompany.anton_mokshyn.touchscreentest flg=0x5000010 cmp=com.android.gallery3d/.app.PackagesMonitor$AsyncService (has extras) }: app is in background uid UidRecord{2dc63ba u0a53 RCVR idle change:idle|uncached procs:0 seq(0,0,0)} 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.app.ActivityThread.handleReceiver(ActivityThread.java:4384) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.app.ActivityThread.access$1600(ActivityThread.java:256) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2102) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:201) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.os.Looper.loop(Looper.java:288) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7870) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: Caused by: android.app.BackgroundServiceStartNotAllowedException: Not allowed to start service Intent { act=android.intent.action.PACKAGE_CHANGED dat=package:com.mycompany.anton_mokshyn.touchscreentest flg=0x5000010 cmp=com.android.gallery3d/.app.PackagesMonitor$AsyncService (has extras) }: app is in background uid UidRecord{2dc63ba u0a53 RCVR idle change:idle|uncached procs:0 seq(0,0,0)} 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1870) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.app.ContextImpl.startService(ContextImpl.java:1826) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.content.ContextWrapper.startService(ContextWrapper.java:776) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.content.ContextWrapper.startService(ContextWrapper.java:776) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at com.android.gallery3d.app.PackagesMonitor.onReceive(PackagesMonitor.java:40) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: at android.app.ActivityThread.handleReceiver(ActivityThread.java:4375) 05-09 01:25:24.465 2187 2187 E AndroidRuntime: ... 9 more
BackgroundServiceStartNotAllowedException | Android Developers (google.cn)
解决方法:
Android O之后 要用startForegroundService 代替 startService