包管理器已死,DeadObjectException

Package Manager has died, DeadObjectException

我们只在一种设备类型上使用我们的应用程序,而且我们经常在该设备上遇到此错误。

PackageManager 的唯一实例是 BootupReceiver:

public class RestartHelper extends BroadcastReceiver
{
     @Override
     public void onReceive(Context context, Intent intent) {
          Logger.getInstance().Log("Restart received");

          Intent i = context.getPackageManager().getLaunchIntentForPackage( context.getPackageName() );
          i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          context.startActivity(i);
     }
}

异常:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.MainActivity}: java.lang.RuntimeException: Package manager has died
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
    at android.app.ActivityThread.access0(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
    at android.os.Handler.dispatchMessage(Handler.java:110)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:5292)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Package manager has died
    at android.app.ApplicationPackageManager.getActivityInfo(ApplicationPackageManager.java:239)
    at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:301)
    at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:281)
    at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:152)
    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60)
    at com.cotris.roosapp.StandardActivity.onCreate(StandardActivity.java:49)
    at com.cotris.roosapp.MainActivity.onCreate(MainActivity.java:64)
    at android.app.Activity.performCreate(Activity.java:5264)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
    ... 11 more
Caused by: android.os.DeadObjectException
    at android.os.BinderProxy.transact(Native Method)
    at android.content.pm.IPackageManager$Stub$Proxy.getActivityInfo(IPackageManager.java:1791)
    at android.app.ApplicationPackageManager.getActivityInfo(ApplicationPackageManager.java:234)
    ... 20 more

这个错误 hardware/system 相关吗?

显然还有另一个 PackageManger 调用,但不仅在 RestartHelper.java 中:

at com.cotris.roosapp.StandardActivity.onCreate(StandardActivity.java:49)

你需要检查里面的代码细节。

android.os.DeadObjectException 意味着您 link 了一些东西,那东西已经不存在了。

我的案例的解决方案是与硬件相关的问题,它会在设备后台造成各种系统进程崩溃。