Skip to content

Commit 542c334

Browse files
committed
feat(app): log crash info
Signed-off-by: Trumeet <[email protected]>
1 parent e1ded55 commit 542c334

File tree

1 file changed

+8
-0
lines changed
  • app/src/main/java/moe/yuuta/mipushtester

1 file changed

+8
-0
lines changed

app/src/main/java/moe/yuuta/mipushtester/App.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package moe.yuuta.mipushtester;
22

33
import android.app.Application;
4+
import android.os.SystemClock;
45

56
import com.crashlytics.android.Crashlytics;
67
import com.crashlytics.android.answers.Answers;
@@ -36,6 +37,13 @@ public void onCreate() {
3637
if (!BuildConfig.DEBUG && !BuildConfig.FABRIC_KEY.equals("disabled")) {
3738
Fabric.with(this, new Crashlytics(), new Answers());
3839
}
40+
Thread.UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler();
41+
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
42+
com.elvishew.xlog.Logger logger = XLog.tag("Crash").build();
43+
logger.e("App crashed", e);
44+
SystemClock.sleep(100);
45+
if (currentHandler != null) currentHandler.uncaughtException(t, e);
46+
});
3947

4048
LoggerInterface newLogger = new LoggerInterface() {
4149
private com.elvishew.xlog.Logger logger =

0 commit comments

Comments
 (0)