Comments (9)
Fragment 是需要一个默认构造方法的,在Fragment里添加一个无参的构造方法应该就可以
from android-app.
一般推荐是在fragment中使用一个newInstance的方法,然后把传入的参数放在fragment本身的argument中,例如
public static YourFragment newInstance(String someArg){
YourFragment rtn = new YourFragment();
Bundle args = new Bundle();
args.putString("argKey",someArg);
rtn.setArgument(args);
return rtn;
}
之后可以从fragment的getArgument()中获取存储的方法,这样就可以很好的避免上面的问题了
from android-app.
楼上正解~ 大家可以尝试修复下这个问题,然后发个pull request〜
from android-app.
大家快点发pull request,我等着merge呢 ;)
from android-app.
尝试重现bug失败。重现环境在nexus7的4,2,2版本和4.3都跑过了。都没有出现上述所说的Force Close。请问是不是已经修复这个bug了。但是我并没有找到相关提交。
from android-app.
好吧这个issue的确还没有被修复。查了一下文档,出现FC的原因是因为在系统需要重新实例化fragment的时候需要一个空的构造方法。(这点之前的同学已经说过了,我又重述了一遍),而我没有重现bug的原因可能是因为没有遇到系统重新实例化fragment吧。
以下是相关文档的引用
All subclasses of Fragment must include a public empty constructor. The framework will often re-instantiate a fragment class when needed, in particular during state restore, and needs to be able to find this constructor to instantiate it. If the empty constructor is not available, a runtime exception will occur in some cases during state restore.
对于@rockybean 的建议,我想说的是。这会不会对代码改动太大
from android-app.
另外相似的问题也在issue #48 中出现。在issue #48 中解决办法是增加无参构造函数。
我想对于一个相同的问题应该采取相同的解决方法。所以有必要讨论一下到底是采用无参构造函数还是使用newInstance方法。
下面列出同样出同样有这个bug的fragment
- UserCollectFragment
- UserCollectListFragment
- UserIntroFragment
- UserLogOutFragment
- WikiFragment
from android-app.
@IceskYsl @com360 你觉得采取哪种方法修复这个bug最好
from android-app.
没有人愿意讨论一下的吗?
要不管理员做个决定?
from android-app.
Related Issues (20)
- 在通过用户名和密码登陆的界面,能不能去掉在登陆失败后清除用户名和密码的功能?
- 实验提问呵呵
- 访问不到http://api.eoe.cn/client HOT 2
- 没有数据
- 连接错误
- 为什么没有数据了 HOT 1
- 网络请求失败,请稍后重试 HOT 1
- 接口是不是不能用了。总是请求不到数据
- I have no idea what I am doing
- 希望在项目主页介绍一下用到的开源项目
- java.lang.NoClassDefFoundError: com.umeng.analytics.MobclickAgent HOT 5
- 项目刚检出,运行报错 (sdk 4.2.2) target=17 HOT 10
- 运行报NoClassDefFoundError HOT 10
- add a scan line ? HOT 7
- onLoadMore() 中if (more_url.equals(null) || more_url.equals("")) 问题 HOT 1
- 在4.0以上的系统,slidingmenu会变得卡和闪,请问有什么解决方案 HOT 9
- 登录用用户名和密码登录不成功? HOT 3
- 建议增加离线阅读功能 HOT 3
- 登录之后获取信息失败 HOT 4
- 滑动菜单卡顿问题欢迎解决 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-app.