/*崩溃处理 */ implementation 'com.tonystark.android:defense_crash:2.0.0' //bugly implementation 'com.tencent.bugly:crashreport_upgrade:1.3.5' implementation'com.tencent.bugly:nativecrashreport:3.3.1'
public class App extends Application implements IExceptionHandler {
initBugly(); } private void initBugly() { CrashReport.initCrashReport(getApplicationContext(), "c50f1d7329", BuildConfig.DEBUG); }
@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); /**/ //MultiDex.install(this); // step1: Initialize the lib. DefenseCrash.initialize(); // step2: Install the fire wall defense. DefenseCrash.install(this); } @Override public void onCaughtException(Thread thread, Throwable throwable, boolean b) { throwable.printStackTrace(); /*todo 收集系统信息*/ /*todo 发送邮件*/ /*bugly 手动上报异常*/ CrashReport.postCatchedException(throwable); } @Override public void onEnterSafeMode() { LogPlus.d("###########onEnterSafeMode###########"); } @Override public void onMayBeBlackScreen(Throwable throwable) { /*重启app*/ Thread thread = Looper.getMainLooper().getThread(); CrashReport.postCatchedException(new ForReportException("onMayBeBlackScreen", throwable)); restartApp(); } /** * 重启app */ public void restartApp() { Intent mStartActivity = new Intent(this, MainActivity.class); int mPendingIntentId = 123456; PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0); }