Nested Fragments using support library v4 revision 11

折月煮酒 提交于 2019-12-03 06:01:14

问题


The last revision of the support library from this morning (Android Support Package v4 revision 11) is supposed to support nested fragments.

In my project I have a fragment that contains a ViewPager and this ViewPager contains several fragments.

I'm calling getSupportFragmentManager() instead of getFragmentManager to use the FragmentManager of the support library.

The problem is I'm still experiencing crashes like :

java.lang.IllegalStateException: Recursive entry to executePendingTransactions
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1012)
    at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:523)
    at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:495)
    at android.support.v4.view.ViewPager.onRestoreInstanceState(ViewPager.java:1221)
    at android.view.View.dispatchRestoreInstanceState(View.java:11910)
    at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2584)
    at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2590)
    at android.view.View.restoreHierarchyState(View.java:11888)
    at android.support.v4.app.Fragment.restoreViewState(Fragment.java:417)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:933)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)

Is there anything I'm doing wrong ? Or the support doesn't support nested fragments for real ?

My transactions are as simple as this:

getSupportFragmentManager().beginTransaction()
                    .replace(R.id.content, new MyFragment()).commit();

回答1:


Try using getChildFragmentManager() instead of getSupportFragmentManager(). this should help



来源:https://stackoverflow.com/questions/13377157/nested-fragments-using-support-library-v4-revision-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!