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();
if (details.runningGameId != 0) { // Create a new activity stack for this launch
// A game is running so launch straight to the game activity ArrayList<Intent> intentStack = new ArrayList<>();
ServerHelper.doStart(AppViewShortcutTrampoline.this, Intent i;
new NvApp("app", details.runningGameId), details, managerBinder);
} // Add the PC view at the back (and clear the task)
else { i = new Intent(AppViewShortcutTrampoline.this, PcView.class);
// No game running - launch to the AppView i.setAction(Intent.ACTION_MAIN);
Intent i = new Intent(getIntent());
i.setClass(AppViewShortcutTrampoline.this, AppView.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i); 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) {
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) { else if (details.state == ComputerDetails.State.OFFLINE) {
// Computer offline - display an error dialog // Computer offline - display an error dialog
@ -93,10 +105,14 @@ 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
// and unbind from the service
if (managerBinder != null) {
managerBinder.stopPolling(); managerBinder.stopPolling();
unbindService(serviceConnection);
managerBinder = null; 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,7 +23,7 @@ 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,
@ -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,