]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/ui/activity/CrashReportingActivity.java
add README.md describing licensing
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / CrashReportingActivity.java
1 package net.ktnx.mobileledger.ui.activity;
2
3 import android.os.Bundle;
4 import android.util.Log;
5
6 import net.ktnx.mobileledger.ui.CrashReportDialogFragment;
7
8 import java.io.PrintWriter;
9 import java.io.StringWriter;
10
11 import androidx.annotation.Nullable;
12 import androidx.appcompat.app.AppCompatActivity;
13
14 public abstract class CrashReportingActivity extends AppCompatActivity {
15     @Override
16     protected void onCreate(@Nullable Bundle savedInstanceState) {
17         super.onCreate(savedInstanceState);
18
19         Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
20             @Override
21             public void uncaughtException(Thread t, Throwable e) {
22                 StringWriter sw = new StringWriter();
23                 PrintWriter pw = new PrintWriter(sw);
24                 e.printStackTrace(pw);
25
26                 Log.e(null, sw.toString());
27
28                 CrashReportDialogFragment df = new CrashReportDialogFragment();
29                 df.setCrashReportText(sw.toString());
30                 df.show(getSupportFragmentManager(), "crash_report");
31             }
32         });
33         Log.d("crash", "Uncaught exception handler set");
34     }
35 }