Skip to content

Commit 4816e12

Browse files
author
Chris Bellew
committed
Fix edge case:when playback is triggered when the app is not currently running, then playback was stopped, and the device was rotated, the intent to show now playing would get fired again, causing the now playing screen to show up again. The fix was to detect if the savedInstanceState was null or not, and to ignore the intents if it wasn't null.
1 parent e14fcb1 commit 4816e12

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

mobile/src/main/java/com/atomjack/vcfp/activities/MainActivity.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ protected void onCreate(Bundle savedInstanceState) {
346346
VoiceControlForPlexApplication.getInstance().cancelNotification();
347347
}
348348

349-
init();
349+
init(savedInstanceState != null);
350350
if(!doingFirstTimeSetup)
351351
doAutomaticDeviceScan();
352352
}
@@ -457,6 +457,14 @@ private void switchToFragment(Fragment fragment) {
457457
}
458458

459459
private void init() {
460+
init(false);
461+
}
462+
463+
// There is an edge case that happens when voice control is triggered when the app is not currently running. The intent passed to
464+
// onCreate() directs the app to show the now playing media, however this intent will get sent again if an orientation change is
465+
// done after stopping playback, which will cause the now playing screen to show up again, when it shouldn't. If init() is passed
466+
// true for previouslyShutDown, we will skip showing the now playing screen.
467+
private void init(boolean previouslyShutDown) {
460468
handler = new Handler();
461469

462470
if(BuildConfig.USE_BUGSENSE) {
@@ -490,9 +498,9 @@ private void init() {
490498
}
491499
logger.d("(init) Intent action: %s", getIntent().getAction());
492500
Intent intent = getIntent();
493-
if(intent.getAction() != null && getIntent().getAction().equals(ACTION_SHOW_NOW_PLAYING)) {
501+
if(intent.getAction() != null && getIntent().getAction().equals(ACTION_SHOW_NOW_PLAYING) && !previouslyShutDown) {
494502
handleShowNowPlayingIntent(intent);
495-
} else if(intent.getAction().equals(com.atomjack.shared.Intent.ACTION_PLAY_LOCAL)) { // this intent will only arrive when playing music. playing video will go to VideoPlayerActivity
503+
} else if(intent.getAction().equals(com.atomjack.shared.Intent.ACTION_PLAY_LOCAL) && !previouslyShutDown) { // this intent will only arrive when playing music. playing video will go to VideoPlayerActivity
496504
handlePlayLocalIntent(intent);
497505
} else {
498506

0 commit comments

Comments
 (0)