From c733a6c3b9275c29de1660c045cc113d190acded Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Sat, 25 Nov 2017 14:22:42 -0500 Subject: [PATCH] Start shortcuts with singleTop, but not all launches This will prevent shortcuts from creating many views, and causing them to leak. However, do not use singleTop for all launches of the view activity, else the edit mode cannot be entered. --- .../java/protect/card_locker/LoyaltyCardViewActivity.java | 3 +++ app/src/main/java/protect/card_locker/ShortcutHelper.java | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java index a1fb19957..e594f375e 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java @@ -322,6 +322,9 @@ public class LoyaltyCardViewActivity extends AppCompatActivity { Intent shortcutIntent = new Intent(this, LoyaltyCardViewActivity.class); shortcutIntent.setAction(Intent.ACTION_MAIN); + // Prevent instances of the view activity from piling up; if one exists let this + // one replace it. + shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); Bundle bundle = new Bundle(); bundle.putInt("id", id); bundle.putBoolean("view", true); diff --git a/app/src/main/java/protect/card_locker/ShortcutHelper.java b/app/src/main/java/protect/card_locker/ShortcutHelper.java index 0b9dbc137..5773e5432 100644 --- a/app/src/main/java/protect/card_locker/ShortcutHelper.java +++ b/app/src/main/java/protect/card_locker/ShortcutHelper.java @@ -103,10 +103,16 @@ class ShortcutHelper { ShortcutInfo prevShortcut = list.get(index); + Intent shortcutIntent = prevShortcut.getIntent(); + + // Prevent instances of the view activity from piling up; if one exists let this + // one replace it. + shortcutIntent.setFlags(shortcutIntent.getFlags() | Intent.FLAG_ACTIVITY_SINGLE_TOP); + ShortcutInfo updatedShortcut = new ShortcutInfo.Builder(context, prevShortcut.getId()) .setShortLabel(prevShortcut.getShortLabel()) .setLongLabel(prevShortcut.getLongLabel()) - .setIntent(prevShortcut.getIntent()) + .setIntent(shortcutIntent) .setIcon(Icon.createWithResource(context, R.drawable.circle)) .setRank(index) .build();