We have enterPictureInPictureMode()
to move an activity from its current form into a picture-in-picture representation.
What is the means by which we revert that, returning the activity to its normal state, besides destroying the activity? There is no exitPictureInPictureMode()
, leavePictureInPictureMode()
, or janeGetMeOffThisCrazyPictureInPictureModeThing()
method on Activity
, and the documentation does not seem to cover an alternative.
I am interested in a solution for Android O, for picture-in-picture mode on mobile devices, though if that works for Android TV too, wonderful!
UPDATE 2017-04-08: If what you want is to return to normal mode when the user clicks the X button to exit picture-in-picture mode, you can do something like this:
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode);
if (!isInPictureInPictureMode) {
getApplication().startActivity(new Intent(this, getClass())
.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
}
}
The key bits are to call startActivity()
to start the current activity again with FLAG_ACTIVITY_REORDER_TO_FRONT
. With a singleTask
activity, you need to call that on some non-Activity
context, such as the Application
singleton. This does not appear to trigger onStop()
or onStart()
, but it does trigger onNewIntent()
(with whatever Intent
you pass to startActivity()
).
question from:
https://stackoverflow.com/questions/43174507/how-do-we-leave-picture-in-picture-mode 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…