JingYeoh/FragmentRigger

报错了 Fragment already added:

huanyuan opened this issue · 2 comments

java.lang.IllegalStateException: Fragment already added: MainFragmentHome1{b6f22cc #0 id=0x7f080084 MainFragmentHome1__b43a1cbe}
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1916)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:765)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

就只有下面的代码
@OverRide
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
switch (checkedId) {
case R.id.main_rb_home1:
LogTools.d("onCheckedChanged()===mainFragmentHome1:");
Rigger.getRigger(this).replaceFragment(mainFragmentHome1, R.id.main_content_f);
break;
case R.id.main_rb_live2:
LogTools.d("onCheckedChanged()===mainFragmentHome1:");
// showFragment(mainFragmentLive2);
Rigger.getRigger(this).replaceFragment(mainFragmentLive2, R.id.main_content_f);
break;
case R.id.main_rb_vod3:
LogTools.d("onCheckedChanged()===mainFragmentHome1:");
Rigger.getRigger(this).replaceFragment(mainFragmentVod3, R.id.main_content_f);
break;
}
}

@huanyuan 在此之前,是否已经使用 Rigger#addFragmentmainFragmentHome1 进行过添加?或者 mainFragmentHome1 是否为单例对象?看你代码的场景是想要实现类似 Tab 功能,推荐使用Rigger#showFragment方法。