片段递归进入executePendingTransactions错误

时间:2013-03-01 06:15:53

标签: android android-fragments android-viewpager android-fragmentactivity android-nested-fragment

我有一个错误:

03-01 11:20:43.453: E/AndroidRuntime(31235): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.qz.Blaze.ServiceStarted flg=0x10 } in com.qz.Blaze.$ServiceStartedReceiver@423540f0
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

在我的活动MyActivity.m_oPager.setCurrentItem(iCurrentView);的行中,该行与下面的此适配器相关:

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;
        }
    }  

2 个答案:

答案 0 :(得分:14)

创建FragmentPagerAdapter时使用getChildFragmentManager()。 e.g:

new FragmentPagerAdapter(getChildFragmentManager());

答案 1 :(得分:2)

使用最新版本的支持库,因为旧版本的supportLibrary不允许嵌套片段。