From e701699dea55cf79fb46b8ecb6ce43355e563c33 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 7 Nov 2016 18:58:59 -0800 Subject: [PATCH] Improve launcher shortcut backstack and stop leaking a ServiceConnection --- .../limelight/AppViewShortcutTrampoline.java | 48 ++++++++++++------- .../com/limelight/utils/ServerHelper.java | 11 +++-- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/limelight/AppViewShortcutTrampoline.java b/app/src/main/java/com/limelight/AppViewShortcutTrampoline.java index 0c6d8fd0..a2b6101e 100644 --- a/app/src/main/java/com/limelight/AppViewShortcutTrampoline.java +++ b/app/src/main/java/com/limelight/AppViewShortcutTrampoline.java @@ -17,6 +17,7 @@ import com.limelight.utils.ServerHelper; import com.limelight.utils.SpinnerDialog; import com.limelight.utils.UiHelper; +import java.util.ArrayList; import java.util.UUID; public class AppViewShortcutTrampoline extends Activity { @@ -72,18 +73,29 @@ public class AppViewShortcutTrampoline extends Activity { // Close this activity finish(); + // Create a new activity stack for this launch + ArrayList intentStack = new ArrayList<>(); + Intent i; + + // Add the PC view at the back (and clear the task) + i = new Intent(AppViewShortcutTrampoline.this, PcView.class); + i.setAction(Intent.ACTION_MAIN); + i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); + intentStack.add(i); + + // Take this intent's data and create an intent to start the app view + i = new Intent(getIntent()); + i.setClass(AppViewShortcutTrampoline.this, AppView.class); + intentStack.add(i); + + // If a game is running, we'll make the stream the top level activity if (details.runningGameId != 0) { - // A game is running so launch straight to the game activity - ServerHelper.doStart(AppViewShortcutTrampoline.this, - new NvApp("app", details.runningGameId), details, managerBinder); - } - else { - // No game running - launch to the AppView - Intent i = new Intent(getIntent()); - i.setClass(AppViewShortcutTrampoline.this, AppView.class); - i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(i); + intentStack.add(ServerHelper.createStartIntent(AppViewShortcutTrampoline.this, + new NvApp("app", details.runningGameId), details, managerBinder)); } + + // Now start the activities + startActivities(intentStack.toArray(new Intent[]{})); } else if (details.state == ComputerDetails.State.OFFLINE) { // Computer offline - display an error dialog @@ -93,9 +105,13 @@ public class AppViewShortcutTrampoline extends Activity { true); } - // We don't want any more callbacks from now on - managerBinder.stopPolling(); - managerBinder = null; + // We don't want any more callbacks from now on, so go ahead + // and unbind from the service + if (managerBinder != null) { + managerBinder.stopPolling(); + unbindService(serviceConnection); + managerBinder = null; + } } }); } @@ -137,12 +153,10 @@ public class AppViewShortcutTrampoline extends Activity { Dialog.closeDialogs(); - if (managerBinder != null) { - unbindService(serviceConnection); - } - if (managerBinder != null) { managerBinder.stopPolling(); + unbindService(serviceConnection); + managerBinder = null; } finish(); diff --git a/app/src/main/java/com/limelight/utils/ServerHelper.java b/app/src/main/java/com/limelight/utils/ServerHelper.java index 7e0d2575..807191cf 100644 --- a/app/src/main/java/com/limelight/utils/ServerHelper.java +++ b/app/src/main/java/com/limelight/utils/ServerHelper.java @@ -23,8 +23,8 @@ public class ServerHelper { computer.localIp : computer.remoteIp; } - public static void doStart(Activity parent, NvApp app, ComputerDetails computer, - ComputerManagerService.ComputerManagerBinder managerBinder) { + public static Intent createStartIntent(Activity parent, NvApp app, ComputerDetails computer, + ComputerManagerService.ComputerManagerBinder managerBinder) { Intent intent = new Intent(parent, Game.class); intent.putExtra(Game.EXTRA_HOST, computer.reachability == ComputerDetails.Reachability.LOCAL ? @@ -34,7 +34,12 @@ public class ServerHelper { intent.putExtra(Game.EXTRA_UNIQUEID, managerBinder.getUniqueId()); intent.putExtra(Game.EXTRA_STREAMING_REMOTE, computer.reachability != ComputerDetails.Reachability.LOCAL); - parent.startActivity(intent); + return intent; + } + + public static void doStart(Activity parent, NvApp app, ComputerDetails computer, + ComputerManagerService.ComputerManagerBinder managerBinder) { + parent.startActivity(createStartIntent(parent, app, computer, managerBinder)); } public static void doQuit(final Activity parent,