Chromecast ATV: distinguish actual shutdown vs. lifecycle from sleep.
Activity lifecycle is different when coming out of sleep mode, since the activity doesn't actually have focus. For whatever reason, this results in an extra onPause/onStop/onStart/onResume sequence before the app is "started". Details: http://stackoverflow.com/questions/25369909/ R=lcwu@chromium.org,byungchul@chromium.org Review URL: https://codereview.chromium.org/864923003 Cr-Commit-Position: refs/heads/master@{#312550}
This commit is contained in:
@ -41,6 +41,7 @@ public class CastShellActivity extends Activity {
|
||||
private CastWindowManager mCastWindowManager;
|
||||
private AudioManager mAudioManager;
|
||||
private BroadcastReceiver mBroadcastReceiver;
|
||||
private boolean mHadFocusWhenPaused = true;
|
||||
|
||||
// Native window instance.
|
||||
// TODO(byungchul, gunsch): CastShellActivity, CastWindowAndroid, and native CastWindowAndroid
|
||||
@ -56,6 +57,16 @@ public class CastShellActivity extends Activity {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Intended to be called from "onStop" to determine if this is a "legitimate" stop or not.
|
||||
* When starting CastShellActivity from the TV in sleep mode, an extra onPause/onStop will be
|
||||
* fired.
|
||||
* Details: http://stackoverflow.com/questions/25369909/
|
||||
*/
|
||||
protected boolean isStopping() {
|
||||
return mHadFocusWhenPaused;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
if (DEBUG) Log.d(TAG, "onCreate");
|
||||
@ -153,10 +164,14 @@ public class CastShellActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if (DEBUG) Log.d(TAG, "onStop");
|
||||
// As soon as the cast app is no longer in the foreground, we ought to immediately tear
|
||||
// everything down.
|
||||
finishGracefully();
|
||||
if (DEBUG) Log.d(TAG, "onStop, window focus = " + hasWindowFocus());
|
||||
|
||||
if (isStopping()) {
|
||||
// As soon as the cast app is no longer in the foreground, we ought to immediately tear
|
||||
// everything down.
|
||||
finishGracefully();
|
||||
}
|
||||
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@ -179,7 +194,8 @@ public class CastShellActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
if (DEBUG) Log.d(TAG, "onPause");
|
||||
if (DEBUG) Log.d(TAG, "onPause, window focus = " + hasWindowFocus());
|
||||
mHadFocusWhenPaused = hasWindowFocus();
|
||||
|
||||
// Release the audio focus. Note that releasing audio focus does not stop audio playback,
|
||||
// it just notifies the framework that this activity has stopped playing audio.
|
||||
|
Reference in New Issue
Block a user