2
FragmentStatePagerAdapterでViewPagerを使用しているときにこの問題が発生し、現在のページを選択しようとしています(つまり、最初のページではなくユーザーに2番目のページを表示しています)例外があります。FragmentManagerはすでにトランザクションを実行中
viewpagerがフラグメントを追加/初期化している、つまり現在のページを設定しようとしている間に現在フラグメントトランザクションを実行しているため、問題は並行性のようです。このような何か:
pagerAdapter = new MyFragmentPagerAdapter(getChildFragmentManager());
viewPager.setAdapter(pagerAdapter);
pagerAdapter.addItems(...) //Addings ID's here for each fragment, this is where the adapter notifies the viewpager
viewPager.setCurrentItem(1); //This is where the two transactions at the same time might happen
質問です:viewpagerは、それが現在のページを設定しても安全ですので、フラグメントの初期化を完了したときにどのように私が知っておくべき?
正確な例外はこれです:
Fatal Exception: java.lang.IllegalStateException: FragmentManager is already executing transactions
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1631)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:679)
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1272)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1120)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1646)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:703)
at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1367)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:768)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2693)
at android.view.View.measure(View.java:18916)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2231)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1307)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1549)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1198)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6268)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:873)
at android.view.Choreographer.doCallbacks(Choreographer.java:676)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:859)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5885)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)