首页 > 移动平台 > 详细

APP崩溃重启

时间:2016-12-09 18:25:37      阅读:252      评论:0      收藏:0      [点我收藏+]

测试了几种APP重启方式,还是这种方式比较靠谱;

public class App extends Application implements
Thread.UncaughtExceptionHandler{
Context context;
private PendingIntent intent; //APP退出后,PendingIntent还存在,设置2秒之后,重新启动你的主Activity
@Override
public void onCreate() {
super.onCreate();
context = this;
//设置Thread Exception Handler
Thread.setDefaultUncaughtExceptionHandler(this);
intent = PendingIntent.getActivity(this, 0,new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
}

@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e("TAG","uncaughtException");
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent);
System.exit(0);
}
 记住在manifest注册你的appliction;
}

APP崩溃重启

原文:http://www.cnblogs.com/shiyeguiji/p/6150601.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!