/** * 解决popTo多个fragment时动画引起的异常问题 */ private void popToFix(String fragmentTag, int flag, final FragmentManager fragmentManager) { if (fragmentManager.getFragments() == null) return; mActivity.preparePopMultiple(); fragmentManager.popBackStackImmediate(fragmentTag, flag); mActivity.popFinish(); mHandler.post(new Runnable() { @Override public void run() { FragmentTransactionBugFixHack.reorderIndices(fragmentManager); } }); }
/** * 分发start事务 * * @param from 当前Fragment * @param to 目标Fragment * @param requestCode requestCode * @param launchMode 启动模式 * @param type 类型 */ void dispatchStartTransaction(FragmentManager fragmentManager, SupportFragment from, SupportFragment to, int requestCode, int launchMode, int type) { fragmentManager = checkFragmentManager(fragmentManager, from); if (fragmentManager == null) return; if ((from != null && from.isRemoving())) { Log.e(TAG, from.getClass().getSimpleName() + " is poped, maybe you want to call startWithPop()!"); return; } checkNotNull(to, "toFragment == null"); if (from != null) { bindContainerId(from.getContainerId(), to); } // process SupportTransaction String toFragmentTag = to.getClass().getName(); TransactionRecord transactionRecord = to.getTransactionRecord(); if (transactionRecord != null) { if (transactionRecord.tag != null) { toFragmentTag = transactionRecord.tag; } if (transactionRecord.requestCode != null && transactionRecord.requestCode != 0) { requestCode = transactionRecord.requestCode; type = TYPE_ADD_RESULT; } if (transactionRecord.launchMode != null) { launchMode = transactionRecord.launchMode; } if (transactionRecord.withPop != null && transactionRecord.withPop) { type = TYPE_ADD_WITH_POP; } // 这里发现使用addSharedElement时,在被强杀重启时导致栈内顺序异常,这里进行一次hack顺序 if (transactionRecord.sharedElementList != null) { FragmentTransactionBugFixHack.reorderIndices(fragmentManager); } } if (type == TYPE_ADD_RESULT) { saveRequestCode(to, requestCode); } if (handleLaunchMode(fragmentManager, to, toFragmentTag, launchMode)) return; switch (type) { case TYPE_ADD: case TYPE_ADD_RESULT: start(fragmentManager, from, to, toFragmentTag, transactionRecord == null ? null : transactionRecord.sharedElementList); break; case TYPE_ADD_WITH_POP: if (from != null) { startWithPop(fragmentManager, from, to, toFragmentTag); } break; } }