IllegalStateException: Can not perform this action after onSaveInstanceState解决办法
来源:互联网 发布:淘宝商城怎么注册 编辑:程序博客网 时间:2024/05/18 01:22
首先我们需要弄清楚onSaveInstanceState方法是在什么时候会被调用,当该Activity即将被销毁前或者按home键退出时调用,来保存Activity数据的,如果在保存玩状态后,桌面通过其他方式启动程序且需要进行Fragment的入栈或弹栈操作就会出错。桌面其他方式如widget、悬浮窗、通知状态栏等方式通过Intent启动程序。
此时拦截该Intent可以在下面的方法中进行
@Overrideprotected void onNewIntent(Intent intent) {// 拦截Intent,做相应处理}
如果在这里拦截了Intent进行Fragment的添加和弹栈就会报错:IllegalStateException: Can not perform this action after onSaveInstanceState。不能在onSaveInstanceState之后立即进行这些操作。解决办法目前找到两种
1、在onResume执行Fragment的入栈或弹栈操作,即在onNewIntent中保存Intent,在onResume()中进行处理。推荐使用
private Intent onHomeIntent; // home键退出后通过intent启动程序@Overrideprotected void onNewIntent(Intent intent) {// 拦截Intent,保存Intent,在onResume中进行处理onHomeIntent = intent;}@Overridepublic void onResume() {if(onHomeIntent != null){// home键退出后通过intent启动程序// dosomething···onHomeIntent = null;}super.onResume();}
new Handler().post(new Runnable() {@Overridepublic void run() {// do something···}});
- IllegalStateException: Can not perform this action after onSaveInstanceState解决办法
- IllegalStateException: Can not perform this action after onSaveInstanceState解决办法
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- Android 异常 IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决Fragment IllegalStateException: Can not perform this action after onSaveInstanceState
- java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- Fragment IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决异常IllegalStateException: Can not perform this action after onSaveInstanceState
- IllegalStateException: Can not perform this action after onSaveInstanceState
- PHP输入流php://input
- 获取分辨率
- NDK的配置
- Cocos-ext部分功能的使用:jsonCpp,CCTableView的滚动和“查看更多”
- android init.rc
- IllegalStateException: Can not perform this action after onSaveInstanceState解决办法
- 人人网2014笔试算法题汇总
- so库的static 变量深入了解
- ECMA 167 - Volume Descriptor Sequence 卷描述符序列
- 信息化为航班显示带来新变化-航显系统研究第88篇
- oracle undo的继续实验
- 百度2014笔试算法题汇总
- 添加Magento新布局文件
- 求分段函数值