Problem: I work in an inherited project (its a very specific project) that requires us to have a custom exception handler that catches the exception, kills the application before the crash occurs and the application restarts (without the crash dialog).
What I tried:
I use the following custom exception handler to restart the Application process:
public class UncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
(…)
@Override
public void uncaughtException(final Thread thread, final Throwable throwable) {
(…)
AppUtils.restartApplication(context);
}
}
And this is the code AppUtils.restartApplication(context):
public final class AppUtils {
(…)
public static void restartApplication(@NonNull final Context context) {
startApplication(context);
closeApplication();
}
private static void startApplication(@NonNull final Context context) {
final Intent rescueIntent = new Intent(context, Activity.class);
rescueIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, rescueIntent, rescueIntent.getFlags());
final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, DateTime.now().plusSeconds(1).getMillis(), pendingIntent);
}
private static void closeApplication() {
Process.killProcess(Process.myPid());
System.exit(SYSTEM_EXIT_STATUS_FORCE_QUIT);
}
}
Before we used Splunk, it worked very well. But now I need to add support for Firebase Crashlytics and Crashlytics, which owns the ExceptionHandler.
So, I came up with two scenarios that do not work for me:
logException Crashlytics , , : , . , - Firebase inicialization logException.
. .