'PackageManager died - DeadObjectException - Transaction failed on small parcel

I've a very simply function like following:

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;
    }
}

Sometimes this crashes at the line getPackageInfo with following 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)
    ...

Any ideas why this can happen? I thought things like this only happen if an app is installed / deinstalled just at the same time, but I have an user who can repeat this and always get's this exception.



Solution 1:[1]

Restrat your Mobile Phone after that;

  1. Clean project
  2. Rebuild Projet
  3. Compile Project

Solution 2:[2]

I am seeing the same problem, but only on Android 6. I am trying to see if adding the PackageManager.GET_META_DATA flag helps. It was suggested in the comments in this similar question: GetPackageInfo results in DeadObjectException

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andronicus
Solution 2 Flyview