Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

android - ViewPager: Recursive entry to executePendingTransactions

I have a ViewPager within a ViewPager and I am getting this exception

09-07 18:30:26.392: ERROR/AndroidRuntime(841): FATAL EXCEPTION: main
    java.lang.IllegalStateException: Recursive entry to executePendingTransactions
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1331)
    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:422)
    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:86)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:453)
    at android.support.v4.view.ViewPager.onAttachedToWindow(ViewPager.java:563)
    at android.view.View.dispatchAttachedToWindow(View.java:7974)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1857)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewGroup.addViewInner(ViewGroup.java:2968)
    at android.view.ViewGroup.addView(ViewGroup.java:2824)
    at android.support.v4.view.ViewPager.addView(ViewPager.java:537)
    at android.view.ViewGroup.addView(ViewGroup.java:2781)
    at android.view.ViewGroup.addView(ViewGroup.java:2761)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:848)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1041)
    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:616)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1359)
    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:422)
    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:86)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:453)
    at android.support.v4.view.ViewPager.onAttachedToWindow(ViewPager.java:563)
    at android.view.View.dispatchAttachedToWindow(View.java:7974)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1857)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewRoot.performTraversals(ViewRoot.java:726)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1944)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:126)
    at android.app.ActivityThread.main(ActivityThread.java:3997)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
    at dalvik.system.NativeStart.main(Native Method)

I am not really sure where this error comes from and I don't know too much about the FragmentManager. Do I need to flush the transactions or something like that? Or is a viewPager within a ViewPager impossible? And yes I know there are other ways to do this but I want the snappness and the scrolling for free. Also I would like to understand how it actually works.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

New version of Support Library v4 (or Android 4.2, ofcourse) resolve this problem much simply. For do this, simply do constructor of your custom FragmentPagerAdapter like this:

public CustomFragmentPagerAdapter(android.support.v4.app.Fragment fragment)
{
    super(fragment.getChildFragmentManager());

    // write your code here
}

This work because new Android version approve using nested Fragments


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...