Fragment not attached to Activity 异常
来源:互联网 发布:淘宝怎样申请客服介入 编辑:程序博客网 时间:2024/04/28 20:17
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就可以了
- 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异常处理
- Schema与数据优化(高性能mysql读书笔记一)
- iOS SDK:预览和打开文档
- strong,retain,weak,assign自匹配宏
- CentOs搭建jdk,tomcat,mysql
- WinDbg 学习之线程相关
- Fragment not attached to Activity 异常
- va_list,va_start,va_arg,va_en
- Android 系统默认壁纸(静态图片和动态壁纸)
- struts 怎么使用 s标签 迭代 map
- (六)快速排序
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 对话框中的子窗口控件
- 吐槽 getopt
- jQuery文档加载完毕的几种写法