您的位置:首页 > 移动开发 > Android开发

android 异常全局捕获并重启

2015-10-29 16:04 471 查看
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