Add crash catch

This commit is contained in:
seven332 committed 2016-03-12 13:32:30 +08:00
1 parent 493b70f885
commit 0cbe074fbb
16 files changed
+545 -4

No files matched your search

@@ -49,13 +49,15 @@ import java.util.concurrent.atomic.AtomicInteger;
import okhttp3.OkHttpClient;
public class EhApplication extends SceneApplication {
public class EhApplication extends SceneApplication implements Thread.UncaughtExceptionHandler {
private static final String TAG = EhApplication.class.getSimpleName();
private static final boolean DEBUG_CONACO = false;
private static final boolean DEBUG_NATIVE_MEMORY = false;
private Thread.UncaughtExceptionHandler mDefaultHandler;
private final AtomicInteger mIdGenerator = new AtomicInteger();
private final SparseArray<Object> mGlobalStuffMap = new SparseArray<>();
private EhCookieStore mEhCookieStore;
@@ -71,6 +73,10 @@ public class EhApplication extends SceneApplication {
@Override
public void onCreate() {
// Prepare to catch crash
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
super.onCreate();
GetText.initialize(this);
@@ -263,4 +269,31 @@ public class EhApplication extends SceneApplication {
}
return application.mDownloadManager;
}
private boolean handleException(Throwable ex) {
if (ex == null) {
return false;
}
try {
ex.printStackTrace();
Crash.saveCrashInfo2File(this, ex);
return true;
} catch (Throwable tr) {
return false;
}
}
@Override
public void uncaughtException(Thread thread, Throwable ex) {
if (!handleException(ex) && mDefaultHandler != null) {
mDefaultHandler.uncaughtException(thread, ex);
}
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
@NonNull
public static String getDeveloperEmail() {
return "ehviewersu$gmail.com".replace('$', '@');
}
}