我很少从DeadObjectException
获得queryIntentActivities
。
这就是我在这个问题上找到的所有内容:http://comments.gmane.org/gmane.comp.handhelds.android.acra/184所以我尝试调整我的代码,如下所示(此代码中的注释来自上面提到的帖子)。
我正在尝试跟随:
旧代码
List<ResolveInfo> ril = pm.queryIntentActivities(mainIntent, 0);
新代码
List<ResolveInfo> ril = null;
try
{
ril = pm.queryIntentActivities(mainIntent, 0);
// process data...
}
catch (DeadObjectException e)
{
// possibly happens because this process is still running but app is currently being updated by the android system
// if this is really true, we can ignore the exception as the complete progress will be stopped anyways...
L.e(e);
}
问题
我无法捕获异常,因为根据定义它永远不会被queryIntentActivities
抛出。我现在可以做些什么来避免这次崩溃?我不想在这里捕捉所有例外情况。
此外,我不确定此异常是否真的发生,我的应用在尝试拨打queryIntentActivities
时已更新,这只是基于上述帖子的假设。谁能证实这一点?
堆栈跟踪
java.lang.RuntimeException: Unable to start receiver com.my.app.receivers.PackageReceiver: java.lang.RuntimeException: Package manager has died
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3641)
at android.app.ActivityThread.access$2000(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1876)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.RuntimeException: Package manager has died
at android.app.ApplicationPackageManager.queryIntentActivitiesAsUser(ApplicationPackageManager.java:765)
at android.app.ApplicationPackageManager.queryIntentActivities(ApplicationPackageManager.java:747)
at com.my.app.utils.AppUtil.a(AppUtil.java:230)
at com.my.app.receivers.PackageReceiver.onReceive(PackageReceiver.java:42)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3634)
... 8 more
Caused by: android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.content.pm.IPackageManager$Stub$Proxy.queryIntentActivities(IPackageManager.java:3940)
at android.app.ApplicationPackageManager.queryIntentActivitiesAsUser(ApplicationPackageManager.java:755)
... 12 more
java.lang.RuntimeException: Package manager has died
at android.app.ApplicationPackageManager.queryIntentActivitiesAsUser(ApplicationPackageManager.java:765)
at android.app.ApplicationPackageManager.queryIntentActivities(ApplicationPackageManager.java:747)
at com.my.app.utils.AppUtil.a(AppUtil.java:230)
at com.my.app.receivers.PackageReceiver.onReceive(PackageReceiver.java:42)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3634)
at android.app.ActivityThread.access$2000(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1876)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
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: Transaction failed on small parcel; remote process probably died
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.content.pm.IPackageManager$Stub$Proxy.queryIntentActivities(IPackageManager.java:3940)
at android.app.ApplicationPackageManager.queryIntentActivitiesAsUser(ApplicationPackageManager.java:755)
... 12 more
android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.content.pm.IPackageManager$Stub$Proxy.queryIntentActivities(IPackageManager.java:3940)
at android.app.ApplicationPackageManager.queryIntentActivitiesAsUser(ApplicationPackageManager.java:755)
at android.app.ApplicationPackageManager.queryIntentActivities(ApplicationPackageManager.java:747)
at com.my.app.utils.AppUtil.a(AppUtil.java:230)
at com.my.app.receivers.PackageReceiver.onReceive(PackageReceiver.java:42)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3634)
at android.app.ActivityThread.access$2000(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1876)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)