public class AppApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
crashinit(this);
}
private crashinit (Context context) {
try {
if (context == null) {
Log.e(TAG, "Cant init, context must not be null");
} else {
application = (Application) context.getApplicationContext();
new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Intent intent = new Intent(application, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
application.startActivity(intent);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(10);
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
android 异常全局捕获并重启
最新推荐文章于 2023-02-11 10:21:39 发布