I have created very simple project that contains 3 activities.

activity 1 have a button can go to activity 2

activity 2 have a button can go to activity 3

activity 3 have a button crash

on a crash button and I try set `throw exception`

```
buttonCrash.setOnclickListener (new View.OnClickListener() {
    @Override
    public void onClick(View v){
        throw new NullPointerException();
    }
});

```

After crash I click re-open, and activity go back to activity 2. how to every crash the app will restart or clear activity stack?

I try to make handle exception class:

```
public class MyExceptionHandler implements Thread.UncaughtExceptionHandler {
  private Activity activity;
  public MyExceptionHandler(Activity a) {
    activity = a;
  }
  @Override
  public void uncaughtException(Thread thread, Throwable ex) {
    Intent intent = new Intent(activity, MainActivity.class);
    intent.putExtra("crash", true);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
      | Intent.FLAG_ACTIVITY_CLEAR_TASK
      | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(MyApplication.getInstance().getBaseContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
    AlarmManager mgr = (AlarmManager) MyApplication.getInstance().getBaseContext().getSystemService(Context.ALARM_SERVICE);
    mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent);
    activity.finish();
    System.exit(2);
  }
}

```

But it's suddenly restart the app, even though I need to show crash dialog first so I can click re-open to open again.

[![enter image description here](https://i.stack.imgur.com/ZR4vh.png)](https://i.stack.imgur.com/ZR4vh.png)