[2110] Fragment 重复问题

This commit is contained in:
yangyakun
2022-09-27 18:52:04 +08:00
parent 0135f5dd1a
commit 980f3c635b
2 changed files with 12 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
package com.mogo.och.bus;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS;
@@ -6,10 +7,10 @@ import android.content.Context;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import com.mogo.map.MogoMapUIController;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.och.bus.constant.BusConst;
@@ -50,14 +51,20 @@ public class BusProvider implements IMogoOCH {
}
private void showFragment() {
FragmentManager supportFragmentManager = activity.getSupportFragmentManager();
if (busFragment == null) {
CallerLogger.INSTANCE.d(TAG, "准备add fragment======");
busFragment = new BusFragment();
activity.getSupportFragmentManager().beginTransaction().add(containerId, busFragment).commitAllowingStateLoss();
Fragment fragmentByTag = supportFragmentManager.findFragmentByTag(BusFragment.TAG);
if(fragmentByTag instanceof BusFragment){
busFragment = (BusFragment)fragmentByTag;
}else {
busFragment = new BusFragment();
}
supportFragmentManager.beginTransaction().add(containerId, busFragment,BusFragment.TAG).commitAllowingStateLoss();
return;
}
CallerLogger.INSTANCE.d(TAG, "准备show fragment");
activity.getSupportFragmentManager().beginTransaction().show(busFragment).commitAllowingStateLoss();
supportFragmentManager.beginTransaction().show(busFragment).commitAllowingStateLoss();
}
private void hideFragment() {

View File

@@ -50,7 +50,7 @@ import java.util.List;
*/
public class BusFragment extends BaseBusTabFragment<BusFragment, BusPresenter>
implements SlidePanelView.OnSlidePanelMoveToEndListener, View.OnClickListener {
private static final String TAG = "BusFragment";
public static final String TAG = "BusFragment";
private TextView mSwitchLine; //切换路线
private TextView mLineName;