Android学习记录(二十一)-crash保护处理
2016-06-07 19:14
495 查看
本文基本都是基于两篇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());
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的代码又不会执行。。。。
11down vote | 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都要修改,就为了把重启改成直接关闭,目前项目的意见是暂时不改。。。
以上就是这几天填的坑。
相关文章推荐
- 解决android使用gson解析json字符串,并使用混淆编译方式打包apk遇到的问题
- listview中EditText,焦点问题
- Android Studio导入Vitamio多媒体开发框架 1
- Android 布局之TableLayout
- Android 加载 SO 库 UnsatisfiedLinkError 错误的原因及解决方案
- 如何分析、定位Android Native Crash
- Android 消息机制学习
- Android布局中实现圆角边框
- 67.Android中的数据存储总结
- Android事件分发机制完全解析(终极版二)
- Android 内存溢出(OOM)解决方案
- Android 水波纹点击效果(Ripple Effect)
- Android的SurfaceView测试代码
- Android内核解读-应用的安装过程
- android bitmap的放大缩小
- android5.0 按键调节音量详解
- Android 编程下 shape 绘制图形
- Android Design Support Library(一):FloatingActionButton、TextInputLayout、TextInputEditText简单用法
- 搞了将近一个月的AS400,现在又转回Android~
- [android]中getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用,getfilesdir