From 377410de6da6437404fc15f9083d7010239cb7ba Mon Sep 17 00:00:00 2001 From: Yi-Ling Chuang Date: Fri, 7 May 2021 09:52:41 +0800 Subject: [PATCH] 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 --- .../settings/core/SettingsBaseActivity.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/core/SettingsBaseActivity.java b/src/com/android/settings/core/SettingsBaseActivity.java index 903805e6ddb..917c3b329a2 100644 --- a/src/com/android/settings/core/SettingsBaseActivity.java +++ b/src/com/android/settings/core/SettingsBaseActivity.java @@ -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