Android学习记录(二十一)-crash保护处理

本文基本都是基于两篇blog:

http://blog.csdn.net/cym_lmy/article/details/24704089

http://blog.csdn.net/xiaanming/article/details/9344703/


为什么要列两篇呢,原来的设计是crash后,2s后重启应用。最近说能不能改成直接关闭app.

然后就开始各种方案。

http://stackoverflow.com/questions/3105673/how-to-kill-an-application-with-all-its-activities


这里遇到两个问题:

1.android.os.Process.killProcess(android.os.Process.myPid());

如果二级的activity crash,只会杀当前的activity,并不会关闭整个程序。
2.当crash发生时,下面的方法无法使用。intent无法跳转到目标初始的activity.如果先杀进程,后写intent的代码,intent的代码又不会执行。。。。

 
 

When the user wishes to exit all open activities, they should press a button which loads the first Activity that runs when your app starts, in my case "LoginActivity".

Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);

The above code clears all the activities except for LoginActivity. LoginActivity is the first activity that is brought up when the user runs the program. Then put this code inside the LoginActivity's onCreate, to signal when it should self destruct when the 'Exit' message is passed.

    if (getIntent().getBooleanExtra("EXIT", false)) {
         finish();
    }

最后总算在:
http://blog.csdn.net/xiaanming/article/details/9344703/
找到了解决方案。理论上是完全可行的。相当于纪录activity的调用链,一个一个finish。
问题是这样代码里所有的activity都要修改,就为了把重启改成直接关闭,目前项目的意见是暂时不改。。。
以上就是这几天填的坑。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值