崩溃后开始活动

时间:2015-12-18 12:44:15

标签: android android-intent nullpointerexception crash

例如,我的应用程序抛出NullPointerException。如何打开活动(例如 - SendCrashLogActivity或已完成Activity1)? 我的方案:enter image description here

您可以使用small demo application

重现此方案

如果不可能,则不应重新启动应用程序。

Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler()
    {
      @Override
      public void uncaughtException (Thread thread, Throwable e)
      {
           Intent intent = new Intent (getApplicationContext(),DrawView.class);
           startActivity(intent); //after calling this method, my application will be frozen. Android 6
      }
    });

2 个答案:

答案 0 :(得分:0)

在startActivity(intent)之后使用以下代码

android.os.Process.killProcess(android.os.Process.myPid());
System.exit(10);

答案 1 :(得分:0)

如果使用finish()方法,活动将被销毁,因此您无法进行上一个活动。 如果您想通过使用意图来进行之前的活动。

否则在清单文件中声明如下。

<activity
        android:name=".CusrrentActivity(activity2)"
        android:label="@string/app_name"
        android:parentActivityName=".PreviousAtivity(activity1)"
        android:screenOrientation="portrait" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.PreviousAtivity(activity2)" />
    </activity>