Merge existing bundle with ActivityOptions

Use Bundle.putAll() to take both the bundle passed in to the
startActivity(Intent, Bundle) and also the new created ActivityOptions
bundle, so no extra info will be lost.

Test: rebuild and add log to make sure all bundle info are kept
Bug: 187471344
Change-Id: I69c2978488f51f1c8ee705dc1bcd1bf17928fe33
This commit is contained in:
Yi-Ling Chuang
2021-05-07 09:52:41 +08:00
parent b3b59d6edd
commit 377410de6d

View File

@@ -147,10 +147,14 @@ public class SettingsBaseActivity extends FragmentActivity {
@Override
public void startActivity(Intent intent, @androidx.annotation.Nullable Bundle options) {
if (!Utils.isPageTransitionEnabled(this) || options != null) {
if (!Utils.isPageTransitionEnabled(this)) {
super.startActivity(intent, options);
return;
}
if (options != null) {
super.startActivity(intent, getMergedBundleForTransition(options));
return;
}
super.startActivity(intent, getActivityOptionsBundle());
}
@@ -168,11 +172,15 @@ public class SettingsBaseActivity extends FragmentActivity {
@Override
public void startActivityForResult(Intent intent, int requestCode,
@androidx.annotation.Nullable Bundle options) {
if (!Utils.isPageTransitionEnabled(this) || requestCode == DEFAULT_REQUEST
|| options != null) {
if (!Utils.isPageTransitionEnabled(this) || requestCode == DEFAULT_REQUEST) {
super.startActivityForResult(intent, requestCode, options);
return;
}
if (options != null) {
super.startActivityForResult(intent, requestCode,
getMergedBundleForTransition(options));
return;
}
super.startActivityForResult(intent, requestCode, getActivityOptionsBundle());
}
@@ -338,6 +346,16 @@ public class SettingsBaseActivity extends FragmentActivity {
"shared_element_view").toBundle();
}
private Bundle getMergedBundleForTransition(@NonNull Bundle options) {
final Bundle mergedBundle = new Bundle();
mergedBundle.putAll(options);
final Bundle activityOptionsBundle = getActivityOptionsBundle();
if (activityOptionsBundle != null) {
mergedBundle.putAll(activityOptionsBundle);
}
return mergedBundle;
}
public interface CategoryListener {
/**
* @param categories the changed categories that have to be refreshed, or null to force