This commit is contained in:
2025-03-05 22:37:23 +08:00
commit 91b3040eed
49 changed files with 1886 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
package com.example.mir4updater.base;
import android.app.Application;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.example.mir4updater.BuildConfig;
import com.tencent.mmkv.MMKV;
public class BaseApplication extends Application {
private static final String TAG = BaseApplication.class.getSimpleName();
@Override
public void onCreate() {
super.onCreate();
if (!BuildConfig.DEBUG) {
catchException();
}
String rootDir = MMKV.initialize(this);
Log.e(TAG, "mmkv root: " + rootDir);
// CrashReport.initCrashReport(getApplicationContext(), "8db7b63e60", false);
xcrash.XCrash.init(this);
}
private void catchException() {
Thread.setDefaultUncaughtExceptionHandler(
new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
Log.e("捕获异常子线程:", Thread.currentThread().getName() +
"在:" + e.getStackTrace()[0].getClassName());
}
}
);
//下面是新增方法!
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
while (true) {
try {
Looper.loop(); //会先执行这个方法,然后在执行下面的异常捕获方法!
} catch (Exception e) {
Log.e("捕获异常主线程:", Thread.currentThread().getName() + "在:" + e.getStackTrace()[0].getClassName());
e.printStackTrace();
}
}
}
});
}
}