Fragment not attached to Activity 异常
来源:互联网 发布:微信积分兑换源码 编辑:程序博客网 时间:2024/05/16 00:41
1、关于Fragment(XXFragment) not attached to Activity 异常。出现该异常,是因为Fragment的还没有Attach到Activity时,调用了如getResource()等,需要上下文Content的函数。解决方法,就是等将调用的代码写在OnStart()中。网上还有几处这样的参考:http://stackoverflow.com/questions/10919240/fragment-myfragment-not-attached-to-activity 回答的主要是在调用
- getResources().getString(R.string.app_name);
- getResources().getString(R.string.app_name);
这个是针对另外一种情况下的解决方式。
2、在使用Fragment保存参数的时候,可能是因为需要保存的参数比较大或者比较多,这种情况下页会引起异常。比如代码
- Bundle b = new Bundle();
- b.putParcelable("bitmap", bitmap2);
- imageRecognitionFragment.setArguments(b);
- Bundle b = new Bundle();
- b.putParcelable("bitmap", bitmap2);
- imageRecognitionFragment.setArguments(b);
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState异常。分析原因:你并不需要系统保存的参数,只要你自己设置的参数能够传递过去,在另外一个Fragment里能够顺利接受就行了,现在android里提供了另外一种形式的提交方式commitAllowingStateLoss(),从名字上就能看出,这种提交是允许状态值丢失的。到此问题得到完美解决,值的传递是你自己控制的。
这里也说一下另外一个问题,bitmap 也可以通过Bundle传递的,使用putParacelable就可以了
3 0
- Fragment not attached to Activity 异常
- 关于Fragment not attached to Activity 异常
- Fragment not attached to Activity 异常
- Fragment not attached to Activity 异常
- Fragment not attached to Activity 异常
- Fragment not attached to activity 异常
- Fragment not attached to Activity 异常
- Fragment not attached to Activity 异常
- Fragment not attached to Activity
- Fragment not attached to Activity
- Fragment not attached to Activity
- Fragment not attached to Activity
- Fragment not attached to Activity
- fragment not attached to Activity
- Fragment(XXFragment) not attached to Activity 异常。
- 关于Fragment(XXFragment) not attached to Activity 异常
- android开发Fragment not attached to Activity异常解决
- llegalStateException: Fragment XXXFragment not attached to Activity异常处理
- Spring 3 MVC深入研究
- Inno Setup 打包的文件以管理员权限运行
- oracle常用函数
- 安利:pynlpir, nlpir 的python端接口, 通过python 使用nlpir / ictclas 2015
- JSP生命周期的实例
- Fragment not attached to Activity 异常
- iOS 网络JSon解析使用框架
- C#System.Diagnostics.Process使用例示
- 释疑spin_lock_irq spin_lock_irqsave spin_unlock_irqrestore spin_lock_bh
- POJ1088 滑雪 简单DP
- [Coursera]数据结构基础_Week3_栈与队列_Q2
- php中重载的概念
- Android项目的图标
- 连续子数组的最大和