Improve launcher shortcut backstack and stop leaking a ServiceConnection

This commit is contained in:
Cameron Gutman 2016-11-07 18:58:59 -08:00
parent 17179bd027
commit e701699dea
2 changed files with 39 additions and 20 deletions

View File

@ -17,6 +17,7 @@ import com.limelight.utils.ServerHelper;
import com.limelight.utils.SpinnerDialog; import com.limelight.utils.SpinnerDialog;
import com.limelight.utils.UiHelper; import com.limelight.utils.UiHelper;
import java.util.ArrayList;
import java.util.UUID; import java.util.UUID;
public class AppViewShortcutTrampoline extends Activity { public class AppViewShortcutTrampoline extends Activity {
@ -72,18 +73,29 @@ public class AppViewShortcutTrampoline extends Activity {
// Close this activity // Close this activity
finish(); finish();
// Create a new activity stack for this launch
ArrayList<Intent> 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) { if (details.runningGameId != 0) {
// A game is running so launch straight to the game activity intentStack.add(ServerHelper.createStartIntent(AppViewShortcutTrampoline.this,
ServerHelper.doStart(AppViewShortcutTrampoline.this, new NvApp("app", details.runningGameId), details, managerBinder));
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);
} }
// Now start the activities
startActivities(intentStack.toArray(new Intent[]{}));
} }
else if (details.state == ComputerDetails.State.OFFLINE) { else if (details.state == ComputerDetails.State.OFFLINE) {
// Computer offline - display an error dialog // Computer offline - display an error dialog
@ -93,9 +105,13 @@ public class AppViewShortcutTrampoline extends Activity {
true); true);
} }
// We don't want any more callbacks from now on // We don't want any more callbacks from now on, so go ahead
managerBinder.stopPolling(); // and unbind from the service
managerBinder = null; if (managerBinder != null) {
managerBinder.stopPolling();
unbindService(serviceConnection);
managerBinder = null;
}
} }
}); });
} }
@ -137,12 +153,10 @@ public class AppViewShortcutTrampoline extends Activity {
Dialog.closeDialogs(); Dialog.closeDialogs();
if (managerBinder != null) {
unbindService(serviceConnection);
}
if (managerBinder != null) { if (managerBinder != null) {
managerBinder.stopPolling(); managerBinder.stopPolling();
unbindService(serviceConnection);
managerBinder = null;
} }
finish(); finish();

View File

@ -23,8 +23,8 @@ public class ServerHelper {
computer.localIp : computer.remoteIp; computer.localIp : computer.remoteIp;
} }
public static void doStart(Activity parent, NvApp app, ComputerDetails computer, public static Intent createStartIntent(Activity parent, NvApp app, ComputerDetails computer,
ComputerManagerService.ComputerManagerBinder managerBinder) { ComputerManagerService.ComputerManagerBinder managerBinder) {
Intent intent = new Intent(parent, Game.class); Intent intent = new Intent(parent, Game.class);
intent.putExtra(Game.EXTRA_HOST, intent.putExtra(Game.EXTRA_HOST,
computer.reachability == ComputerDetails.Reachability.LOCAL ? computer.reachability == ComputerDetails.Reachability.LOCAL ?
@ -34,7 +34,12 @@ public class ServerHelper {
intent.putExtra(Game.EXTRA_UNIQUEID, managerBinder.getUniqueId()); intent.putExtra(Game.EXTRA_UNIQUEID, managerBinder.getUniqueId());
intent.putExtra(Game.EXTRA_STREAMING_REMOTE, intent.putExtra(Game.EXTRA_STREAMING_REMOTE,
computer.reachability != ComputerDetails.Reachability.LOCAL); 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, public static void doQuit(final Activity parent,