键f0:index 1不再存在片段

时间:2013-07-29 22:22:17

标签: android android-fragments android-viewpager fragmentstatepageradapter

我有一个漂亮的ViewPager / FragmentStatePagerAdapter工作在我的应用程序上但是在将片段手动添加到FragmentManager后,我开始在旋转屏幕TWICE 时出现此异常

堆栈跟踪:

07-29 19:10:22.360: E/FragmentManager(712): Fragement no longer exists for key f0: index 1
07-29 19:10:22.360: E/FragmentManager(712): Activity state:
07-29 19:10:22.407: D/FragmentManager(712):   Active Fragments in 4608be98:
07-29 19:10:22.410: D/FragmentManager(712):     #0: RESTFragment{46005fb0 #0 RESTFragment}
07-29 19:10:22.410: D/FragmentManager(712):       mFragmentId=#0 mContainerId=#0 mTag=RESTFragment
07-29 19:10:22.410: D/FragmentManager(712):       mState=5 mIndex=0 mWho=android:fragment:0 mBackStackNesting=0
07-29 19:10:22.410: D/FragmentManager(712):       mAdded=true mRemoving=false mResumed=true mFromLayout=false mInLayout=false
07-29 19:10:22.410: D/FragmentManager(712):       mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
07-29 19:10:22.419: D/FragmentManager(712):       mRetainInstance=true mRetaining=false mUserVisibleHint=true
07-29 19:10:22.419: D/FragmentManager(712):       mFragmentManager=FragmentManager{45fbe180 in MyActivity{46016180}}
07-29 19:10:22.419: D/FragmentManager(712):       mActivity=com.argeniss.theguymob.frontend.MyActivity@46016180
07-29 19:10:22.419: D/FragmentManager(712):     #1: null
07-29 19:10:22.419: D/FragmentManager(712):   Added Fragments:
07-29 19:10:22.419: D/FragmentManager(712):     #0: RESTFragment{46005fb0 #0 RESTFragment}
07-29 19:10:22.419: D/FragmentManager(712):     #1: MyPageFragment{46024658}
07-29 19:10:22.419: D/FragmentManager(712):   FragmentManager misc state:
07-29 19:10:22.419: D/FragmentManager(712):     mActivity=null
07-29 19:10:22.419: D/FragmentManager(712):     mContainer=null
07-29 19:10:22.430: D/FragmentManager(712):     mCurState=0 mStateSaved=true mDestroyed=true
07-29 19:10:22.430: D/FragmentManager(712):     mAvailIndices: [1]
07-29 19:10:22.430: E/com.argeniss.theguymob.frontend.MyActivity(712): Fragement no longer exists for key f0: index 1

这是我手动将片段添加到管理器的代码:

private void addFragmentToManager() {
    String fragmentTag = RESTFragment.TAG;
    FragmentManager fragmentManager = getSupportFragmentManager();

    restFragment = (RESTFragment) fragmentManager.findFragmentByTag(fragmentTag);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (restFragment == null) {
        restFragment = new RESTFragment();
        fragmentTransaction.add(restFragment, fragmentTag);
    }

    // Adds the transaction to the fragment manager.
    fragmentTransaction.commit();
    fragmentManager.executePendingTransactions();
}

0 个答案:

没有答案