Android开发问题之Fragment not attached to Activity
来源:互联网 发布:淘宝充的话费可以退吗 编辑:程序博客网 时间:2024/05/20 07:54
1、问题的发生
该错误经常发生在fragment的线程中执行了一个耗时操作,线程在执行完毕后会调用getResources来更新ui。如果在线程操作没有完成,就调用getActivity().recreate()重新加载activity或屏幕旋转,这时就会出现Fragment not attached to Activity的错误
2、问题解决
在调用getResources更新ui的地方添加判断
if(isAdded()){ resultTv.setText(getResources().getText(R.string.hello_world));}
isAdded()方法可以判断当前的Fragment是否已经添加到Activity中,只有当Fragment已经添加到Activity中时才执行getResources()等方法。
阅读全文
0 0
- Android开发问题之Fragment not attached to Activity
- android开发Fragment not attached to Activity异常解决
- Android问题解决之Fragment not attached to Activity异常
- Android - Fragment StepCounterStaticFragment not attached to Activity
- Android IllegalStateException: Fragment not attached to Activity
- Android IllegalStateException: 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
- Android Fragment IllegalStateException: Fragment not attached to Activity
- Android bug Fragment MyFragment not attached to Activity
- Fragment not attached to Activity 异常
- 关于Fragment not attached to Activity 异常
- Fragment MyFragment not attached to Activity
- Fragment MyFragment not attached to Activity
- Discrollview自定义的动态布局
- Spring MVC @ModelAttribute详解
- 关于身份证验证
- 260. Single Number III
- Android-Ubuntu系统中使用Android studio并导入Android5.1源码
- Android开发问题之Fragment not attached to Activity
- 1.Node.js 接入微信公众平台开发
- PyQt5+Python3.5.3-64bit开发环境搭建
- ContentProvider 小结
- (个人)AR电子书系统创新实训第三周(1)
- 火狐快捷键
- 关于WdatePicker.js插件日期精确度问题
- 如何自动生成文本摘要
- RSA非对称加密工具JAVA实现