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,13 +69,16 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
explicitLocales, explicitLocales,
null /* appPackageName */, null /* appPackageName */,
this); this);
if (getFragmentManager().findFragmentByTag(CHILD_FRAGMENT_NAME) == null) {
getFragmentManager() getFragmentManager()
.beginTransaction() .beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_frame, mSelector) .replace(R.id.content_frame, mSelector, CHILD_FRAGMENT_NAME)
.addToBackStack(PARENT_FRAGMENT_NAME) .addToBackStack(PARENT_FRAGMENT_NAME)
.commit(); .commit();
} }
}
@Override @Override
public void onDestroy() { public void onDestroy() {