Add FLAG_ACTIVITY_SINGLE_TOP to shortcuts intent
This is to simplify the shortcut launch flow on large screen devices
when launching the same shortcut, which also improves the performance.
FLAG_ACTIVITY_CLEAR_TOP flag is used for the launch a shortcut. When
launching a shortcut whose activity is in the background on a large
screen device, the background activity is cleared by the system and a
new activity is started. Thus, the activity goes though the complete
deep link flow that invokes the trampoline homepage activity to start
the target page.
After the change, the system will bring the background activity to the
foreground rather than kill it and start a new one.
Test: create a shortcut and observe the adb log
Fix: 234681140
Change-Id: Id922af1f59a6a64ea6f6150cf6fea92808a6de65
diff --git a/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java b/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java
index c871e9f..89ee19b 100644
--- a/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java
+++ b/src/com/android/settings/shortcut/CreateShortcutPreferenceController.java
@@ -46,6 +46,7 @@
import com.android.settings.R;
import com.android.settings.Settings;
import com.android.settings.Settings.TetherSettingsActivity;
+import com.android.settings.activityembedding.ActivityEmbeddingUtils;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.gestures.OneHandedSettingsUtils;
import com.android.settings.overlay.FeatureFactory;
@@ -127,7 +128,7 @@
return false;
}
final Intent shortcutIntent = createResultIntent(
- buildShortcutIntent(info),
+ buildShortcutIntent(uiContext, info),
info, clickTarget.getTitle());
mHost.setResult(Activity.RESULT_OK, shortcutIntent);
logCreateShortcut(info);
@@ -210,10 +211,14 @@
info.activityInfo.name);
}
- private static Intent buildShortcutIntent(ResolveInfo info) {
- return new Intent(SHORTCUT_PROBE)
+ private static Intent buildShortcutIntent(Context context, ResolveInfo info) {
+ Intent intent = new Intent(SHORTCUT_PROBE)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP)
.setClassName(info.activityInfo.packageName, info.activityInfo.name);
+ if (ActivityEmbeddingUtils.isEmbeddingActivityEnabled(context)) {
+ intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ }
+ return intent;
}
private static ShortcutInfo createShortcutInfo(Context context, Intent shortcutIntent,
@@ -277,8 +282,8 @@
ResolveInfo ri = context.getPackageManager().resolveActivity(si.getIntent(), 0);
if (ri != null) {
- updatedShortcuts.add(createShortcutInfo(context, buildShortcutIntent(ri), ri,
- si.getShortLabel()));
+ updatedShortcuts.add(createShortcutInfo(context,
+ buildShortcutIntent(context, ri), ri, si.getShortLabel()));
}
}
}