我有一个非常简单的功能,如下所示:
public static boolean isAppInstalled(String packageName) {
PackageManager pm = MainApp.get().getPackageManager();
try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
有时这会在
getPackageInfo
行崩溃,并带有以下stacktrace:java.lang.RuntimeException: Package manager has died
at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:151)
... code in my app => getPackageInfo line above ...
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:505)
at android.content.pm.IPackageManager$Stub$Proxy.getPackageInfo(IPackageManager.java:2151)
at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:145)
...
任何想法为什么会发生这种情况?我以为这样的事情只有在同时安装/卸载应用程序的情况下才会发生,但是我有一个用户可以重复此操作并始终得到此异常。
最佳答案
之后重新启动您的手机;
关于android - PackageManager死亡-DeadObjectException-小宗宗交易失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52915711/