Merge "[Settings] Do not create fragment twice" into main

This commit is contained in:
Zoey Chen
2024-08-15 02:27:14 +00:00
committed by Android (Google) Code Review

View File

@@ -39,6 +39,7 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
implements LocalePickerWithRegion.LocaleSelectedListener, MenuItem.OnActionExpandListener { implements LocalePickerWithRegion.LocaleSelectedListener, MenuItem.OnActionExpandListener {
private static final String TAG = LocalePickerWithRegionActivity.class.getSimpleName(); private static final String TAG = LocalePickerWithRegionActivity.class.getSimpleName();
private static final String PARENT_FRAGMENT_NAME = "localeListEditor"; private static final String PARENT_FRAGMENT_NAME = "localeListEditor";
private static final String CHILD_FRAGMENT_NAME = "LocalePickerWithRegion";
private LocalePickerWithRegion mSelector; private LocalePickerWithRegion mSelector;
@@ -68,12 +69,15 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
explicitLocales, explicitLocales,
null /* appPackageName */, null /* appPackageName */,
this); this);
getFragmentManager()
.beginTransaction() if (getFragmentManager().findFragmentByTag(CHILD_FRAGMENT_NAME) == null) {
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) getFragmentManager()
.replace(R.id.content_frame, mSelector) .beginTransaction()
.addToBackStack(PARENT_FRAGMENT_NAME) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit(); .replace(R.id.content_frame, mSelector, CHILD_FRAGMENT_NAME)
.addToBackStack(PARENT_FRAGMENT_NAME)
.commit();
}
} }
@Override @Override