1 package net.ktnx.mobileledger.ui.activity;
3 import android.os.Bundle;
4 import android.util.Log;
6 import net.ktnx.mobileledger.ui.CrashReportDialogFragment;
8 import java.io.PrintWriter;
9 import java.io.StringWriter;
11 import androidx.annotation.Nullable;
12 import androidx.appcompat.app.AppCompatActivity;
14 public abstract class CrashReportingActivity extends AppCompatActivity {
16 protected void onCreate(@Nullable Bundle savedInstanceState) {
17 super.onCreate(savedInstanceState);
19 Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
21 public void uncaughtException(Thread t, Throwable e) {
22 StringWriter sw = new StringWriter();
23 PrintWriter pw = new PrintWriter(sw);
24 e.printStackTrace(pw);
26 Log.e(null, sw.toString());
28 CrashReportDialogFragment df = new CrashReportDialogFragment();
29 df.setCrashReportText(sw.toString());
30 df.show(getSupportFragmentManager(), "crash_report");
33 Log.d("crash", "Uncaught exception handler set");