Home » Android » android – Fragment Recursive entry to executePendingTransactions Error

android – Fragment Recursive entry to executePendingTransactions Error

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have an error as:

03-01 11:20:43.453: E/AndroidRuntime(31235): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.qz.Blaze.ServiceStarted flg=0x10 } in [email protected]
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:766)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.os.Handler.handleCallback(Handler.java:615)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.os.Looper.loop(Looper.java:137)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.app.ActivityThread.main(ActivityThread.java:4921)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at java.lang.reflect.Method.invokeNative(Native Method)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at java.lang.reflect.Method.invoke(Method.java:511)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at dalvik.system.NativeStart.main(Native Method)
03-01 11:20:43.453: E/AndroidRuntime(31235): Caused by: java.lang.IllegalStateException: Recursive entry to executePendingTransactions
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1011)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:522)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:494)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:475)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.qz.Blaze.Fragment.onCreateView(Fragment.java:53)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1011)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.populate(ViewPager.java:880)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:433)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.qz.XXX.XXXX.Init(.java:588)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.qz.Blaze..access$3(.java:546)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.qz.Blaze.$ServiceStartedReceiver.onReceive(.java:2416)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:756)
03-01 11:20:43.453: E/AndroidRuntime(31235):    ... 9 more

At the line where I do MyActivity.m_oPager.setCurrentItem(iCurrentView); in my Activity which is related with this adapter below:

public class FragmentPagerAdapter extends FragmentPagerAdapter
    {
        final int PAGE_COUNT_LOGGED_IN = 5;
        final int PAGE_COUNT_LOGGED_OUT = 2;
        TextView oTextView = null;
        LayoutInflater inflater = null;
        PagerTabStrip m_oPageTabStrip = null;
        String m_strTab = null;
        String[] m_strArray = null;     
        Context m_oContext = null;

        /** Constructor of the class */
        public FragmentPagerAdapter (Context context, FragmentManager oFragmentManager) 
        {
            super (oFragmentManager);
            m_oContext = context;
        }


        /** This method will be invoked when a page is requested to create */
        @Override
        public Fragment getItem(int arg0) 
        {       
            Fragment myFragment = new Fragment ();
            Bundle data = new Bundle();
            data.putInt("current_page", arg0+1);
            myFragment.setArguments(data);
            return myFragment;
        }

        /** Returns the number of pages */
        @Override
        public int getCount() 
        {       
            if (Utility.m_bIsLoggedIn == true)
            {
                return PAGE_COUNT_LOGGED_IN;
            }
            else
            {
                return PAGE_COUNT_LOGGED_OUT;
            }
        }

        @Override
        public CharSequence getPageTitle(int position) 
        {
            String strText = " ";

            switch(position)
            {
            case 0:
                strText = "";
                break;
            case 1:
                strText = "";
                break;
            case 2:
                strText = "";
                break;
            case 3:
                strText = "";
                break;
            case 4:
                strText = "";
                break;
            }

             Spannable s = Spannable.Factory.getInstance().newSpannable(strText);
             Typeface tt = Typeface.createFromAsset(m_oContext.getAssets(), "fonts/fontinsansbolditalic.ttf");
             s.setSpan (new CustomTypefaceSpan ("", tt), 0, strText.length(),Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            return s;
        }
    }  
How to&Answers:

Use getChildFragmentManager() when creating FragmentPagerAdapter. e.g:

new FragmentPagerAdapter(getChildFragmentManager());

Answer:

Use the latest version of the support library as the older version of supportLibrary does not allow nested fragments.