Android Ereza CustomActivity OnCrash startActivity with Intential
我一直在尝试在我的应用程序中实现一个自定义UncaughtExceptionHandler,我发现了库Ereza/CustomActivityOnCrash 我已经添加了README()中描述的所有代码,但似乎仍然无法使其正常工作。当我强迫我的应用程序崩溃时,会弹出一个白色屏幕,然后立即消失 你知道这是什么原因吗?下面是我的一些代码 雄激素单Android Ereza CustomActivity OnCrash startActivity with Intential,android,android-intent,start-activity,uncaughtexceptionhandler,Android,Android Intent,Start Activity,Uncaughtexceptionhandler,我一直在尝试在我的应用程序中实现一个自定义UncaughtExceptionHandler,我发现了库Ereza/CustomActivityOnCrash 我已经添加了README()中描述的所有代码,但似乎仍然无法使其正常工作。当我强迫我的应用程序崩溃时,会弹出一个白色屏幕,然后立即消失 你知道这是什么原因吗?下面是我的一些代码 雄激素单 <activity android:name="com.test.SplashActivity" andro
<activity
android:name="com.test.SplashActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.test.MainActivity"
android:label="MainActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="cat.ereza.customactivityoncrash.RESTART" />
</intent-filter>
</activity>
<activity
android:name="com.test.ErrorActivity"
android:label="Error"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="cat.ereza.customactivityoncrash.ERROR" />
</intent-filter>
</activity>
Hi将以下代码放入应用程序类中,并根据需要修改以处理未处理的异常:
@Override
public void onCreate() {
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable e) {
handleUncaughtException(thread, e);
}
});
}
public void handleUncaughtException(Thread thread, Throwable e) {
e.printStackTrace(); // not all Android versions will print the stack trace automatically
//Work what you want to do....
//start new activity with clearing task
Intent intent = new Intent(this, ActivityClass.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
//end
System.exit(2); // kill off the crashed app
}
希望这有帮助,我正在我的应用程序中使用。。。有效。在应用程序类中放入以下代码,并根据需要修改以处理未处理的异常:
@Override
public void onCreate() {
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable e) {
handleUncaughtException(thread, e);
}
});
}
public void handleUncaughtException(Thread thread, Throwable e) {
e.printStackTrace(); // not all Android versions will print the stack trace automatically
//Work what you want to do....
//start new activity with clearing task
Intent intent = new Intent(this, ActivityClass.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
//end
System.exit(2); // kill off the crashed app
}
希望这有帮助,我正在我的应用程序中使用。。。有效。经过进一步调查,我发现这个库/代码不喜欢在调试模式下运行。如果我在我的设备上安装了应用程序并从那里启动它(而不是使用Android Studio的调试),它似乎工作得很好。经过进一步的调查,我发现这个库/代码不喜欢在调试模式下运行。如果我在我的设备上安装了应用程序并从那里启动它(而不是使用Android Studio的调试),它似乎工作正常。这很可能是由于
错误活动
没有被指定为另一个进程的一部分
从库文档中,关于自定义错误活动的使用:
如果使用此选项,则必须在AndroidManifest.xml
中声明活动,并将过程设置为:error\u activity
这很可能是由于未将错误活动
指定为另一个进程的一部分造成的
从库文档中,关于自定义错误活动的使用:
如果使用此选项,则必须在AndroidManifest.xml
中声明活动,并将过程设置为:error\u activity
请提供logcatplease提供logcatHi Ramesh,是的,这是一个很好的解决方案,但我想将错误记录到Crashlytics,并重新启动应用程序。我正在更新“启动活动”的答案,清除以前的任务。。您可以将此作为答案。您好,Ramesh,是的,这是一个很好的解决方案,但我想将错误记录到Crashlytics,并重新启动应用程序。我正在使用“清除上一个任务”更新启动活动的答案。。你可以接受这个答案。。