我仅在不同设备上的Android 6.0 - 6.0.1上获得此例外。
Fatal Exception: java.lang.RuntimeException: Package manager has died
at android.app.ApplicationPackageManager.getPackagesForUid(ApplicationPackageManager.java:632)
at android.provider.Settings.getPackageNameForUid(Settings.java:14462)
at android.provider.Settings.canDrawOverlays(Settings.java:1569)
at com.myproject.project.services.MyService.removeicon(MyService.java:240)
at com.myproject.project.services.MyService.access$200(MyService.java:57)
at com.myproject.project.services.MyService$1.run(MyService.java:232)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Binder.java)
at android.os.BinderProxy.transact(Binder.java:503)
at android.content.pm.IPackageManager$Stub$Proxy.getPackagesForUid(IPackageManager.java:3746)
at android.app.ApplicationPackageManager.getPackagesForUid(ApplicationPackageManager.java:630)
at android.provider.Settings.getPackageNameForUid(Settings.java:14462)
at android.provider.Settings.canDrawOverlays(Settings.java:1569)
at com.myproject.project.services.MyService.removeicon(MyService.java:240)
at com.myproject.project.services.MyService.access$200(MyService.java:57)
at com.myproject.project.services.MyService$1.run(MyService.java:232)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
我知道这是因为我使用Settings.canDrawOverlays(this)而不是Settings.canDrawOverlays(getApplicationContext()),但我不确定。我之前从未遇到过DeadObjectException。你能解释我什么时候可以捕获这个异常以及如何避免这个异常。感谢。