1

For example, my application throws a NullPointerException. How to open the Activity (for example – SendCrashLogActivity, or finished Activity1)? My scenario:enter image description here

You can reproduce this scenario using small demo application

If it is impossible then application should not be restarted.

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
      }
    });
Faizan Mubasher
  • 4,427
  • 11
  • 45
  • 81
VKDev
  • 604
  • 7
  • 18
  • 2
    Possible duplicate of [android: Handle Application Crash and start a particular Activity](http://stackoverflow.com/questions/27829955/android-handle-application-crash-and-start-a-particular-activity) – Rami Dec 18 '15 at 12:50
  • 1
    Here's a better idea : instead of spending time coding to recover from crashes, spend the time to improve your code so it doesn't crash... – 2Dee Dec 18 '15 at 12:59
  • 2Dee, You can move your comment to the answer, Ill make you answer as best) ...Ill try to use this library https://github.com/Ereza/CustomActivityOnCrash – VKDev Dec 24 '15 at 11:29

2 Answers2

1

Use below code after startActivity(intent)

android.os.Process.killProcess(android.os.Process.myPid());
System.exit(10);
ondermerol
  • 524
  • 1
  • 11
  • 29
1

If use finish() method the activity is destroyed, so you can not go previous activity. If you want to go previous activity by using intent.

otherwise in manifest file declare like this.

<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>
Prathap Badavath
  • 1,621
  • 2
  • 20
  • 24