您的位置:首页 > 编程语言 > Java开发

java.lang.IllegalStateException: Fragment already active

2014-09-02 10:17 330 查看
1. 问题描述:

在使用Fragment的setArguments(Bundle
args)来传递参数到Fragment时,如果该Fragment是之前已经new出来的Fragment,

不是本次重新new出来的Fragment,这是再次调用setArguments(Bundle
args) 则会发生该Exception。

2.解决方案:

Reading the setArguments(Bundle
args) source will help you understand:
/**
* Supply the construction arguments for this fragment.  This can only
* be called before the fragment has been attached to its activity; that
* is, you should call it immediately after constructing the fragment.  The
* arguments supplied here will be retained across fragment destroy and
* creation.
*/
public void setArguments(Bundle args) {

if (mIndex >= 0) {
throw new IllegalStateException("Fragment already active");
}
mArguments = args;
}


You cannot use setArguments(Bundle
args) again in your code on the same Fragment.
What you want to do I guess is either create a new Fragment of
and set the arguments again. Or you can usegetArguments() and
then use the 
put
 methods
of bundle to change it's values.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java.lang.IllegalSta
相关文章推荐