android: Handle Application Crash and start a particular Activity

后端 未结 5 561
-上瘾入骨i
-上瘾入骨i 2020-12-09 04:18

I have an app and if the app crashes in a particular activity, it restarts at one of the intermediate parent activities.

This is a problem for me since I have some

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 05:16

    First, create and set the App class in your AndroidManifest.xml and

    android:name=".App"
    android:clearTaskOnLaunch="true"
    

    then put this code in the App class

    public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
         Thread.setDefaultUncaughtExceptionHandler(
                new Thread.UncaughtExceptionHandler() {
                    @Override
                    public void uncaughtException(Thread thread, Throwable e) {
                        Log.d("AppCrash", "Error just lunched ");
                    }
                });
    }}
    

    Debug Log Screenshot:

提交回复
热议问题