【Android】java.lang.IllegalStateException: Recursive entry to executePendingTransactions
正文
错误
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:9966)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2617)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2623)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2623)
at android.view.View.restoreHierarchyState(View.java:9944)
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.attachFragment(FragmentManager.java:1264)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
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:608)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:4987)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
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:9966)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2617)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2623)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2623)
at android.view.View.restoreHierarchyState(View.java:9944)
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.attachFragment(FragmentManager.java:1264)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
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:608)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:4987)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
第一次使用没有问题(add),第二次使用时就报这个错(attach)。
场景
嵌套Fragment使用(最外层FragmentActivity,Fragment中使用ViewPager再嵌套Fragment使用)
解决
嵌套Fragment设置PageAdapter时要使用getChildFragmentManager。