commitAllowingStateLoss()
来源:互联网 发布:韦德生涯场均数据 编辑:程序博客网 时间:2024/06/04 19:05
下边两个问题,是在开发中碰到的一些关于Fragment的偶发性的问题,今天时间比较多,就在网上搜了一些解决方式:
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);
这个是针对另外一种情况下的解决方式。
2、在使用Fragment保存参数的时候,可能是因为需要保存的参数比较大或者比较多,这种情况下页会引起异常。比如代码
- 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就可以了
- 顶
- 6
- 踩
阅读全文
0 0
- commitAllowingStateLoss()
- commitAllowingStateLoss()
- commitAllowingStateLoss()
- commitAllowingStateLoss
- commitAllowingStateLoss()
- Fragment commitAllowingStateLoss()
- commit()和commitallowingstateloss()
- commitallowingstateloss 和commit的区别
- Fragment commit 替换成 commitAllowingStateLoss()
- commitallowingstateloss 和commit的区别
- FragmentTransaction的commit和commitAllowingStateLoss的区别
- FragmentTransaction的commit和commitAllowingStateLoss的区别
- FragmentTransaction的commit和commitAllowingStateLoss的区别
- FragmentTransaction的commit和commitAllowingStateLoss的区别
- FragmentTransaction的commit和commitAllowingStateLoss的区别
- FragmentTransaction的commit和commitAllowingStateLoss的区别
- FragmentTransaction的commit和commitAllowingStateLoss的区别
- FragmentTransaction的commit和commitAllowingStateLoss的区别
- 接口
- 数据结构与算法分析 c++ 平衡二叉树 AvlTree
- YOLO v2 训练自己的图像数据
- Word Vectors详解(2)
- 什么是md5
- commitAllowingStateLoss()
- 纯css实现图片翻转效果
- JDP
- 欢迎使用CSDN-markdown编辑器
- Category初见
- Google advances AI with ‘one model to learn them all
- 侧滑栏的右上角图标修改
- 172 Factorial Trailing Zeroes
- 第八届河南省程序设计大赛 D.引水工程【最小生成树相关】