Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do We Leave Picture-In-Picture Mode?

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()).

like image 266
CommonsWare Avatar asked Apr 02 '17 23:04

CommonsWare


People also ask

Where is Picture in Picture in settings?

Open Settings. Tap Apps & notifications. Go to Advanced > Special app access. Select Picture-in-picture.

How to turn off picture in Picture mode on Android devices?

Now, tap on Picture in Picture. Toggle off the switch next to Start PiP Automatically. This setting ensures that picture-in-picture mode is only enabled when you tap the PiP mode icon and not when you navigate to Home Screen. That’s all for now!

Can an activity decide to leave picture-in-Picture mode?

I don't think the activity can decide to leave Picture-in-picture mode. The activity entering PIP mode goes into the paused state, but remains started. If the user taps the PIP activity, the system shows a menu for the user to interact with; no touch events reach the activity while it is in the PIP state.

How do I turn off picture-in-Picture mode on my Raspberry Pi?

To do that, go to Settings > General > Picture-in-Picture and turn off the switch next to Start PiP Automatically. Note: Even with the setting above turned off, you can still open videos in Picture-in-Picture mode manually via the PiP icon or the two-fingered double-tap gesture.

How to enable picture in Picture mode on iPhone?

How to Enable Picture in Picture Mode on iPhone 1 Play a Video on any supported app 2 Now tap on the PiP Mode icon or navigate to Home Screen, the video will instantly minimize 3 Hold & drag the minimized screen anywhere, according to your preference.


2 Answers

  1. Move the activity to the back

    activity.moveTaskToBack(false /* nonRoot */); 
  2. restore the activity to the front

    Intent startIntent = new Intent(PipActivity.this, PipActivity.class); startIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); activity.startActivity(startIntent); 
like image 135
rds Avatar answered Sep 18 '22 15:09

rds


I had the same problem:

  • MainActivity opens VideoPlayerActivity which has PIP mode enabled.
  • Press the back button to go to the PIP mode.
  • Press back button again until I exit from MainActivity.
  • Press close (X) button on the PIP window.
  • Open application, It will open VideoPlayerActivity.

While none of the above solutions work for me, I found out that the only way to listen to X button is to override onStop.

When the activity is restored from PIP, onResume and onPictureInPictureModeChanged are called, when the X button is clicked, the onStop and onPictureInPictureModeChanged are called.

So I tried to call finish() inside onPictureInPictureModeChanged when the onStop is alreay called.

override fun onStop() {     super.onStop()     onStopCalled = true }  override fun onResume() {     super.onResume()     onStopCalled = false }  override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {         if (isInPictureInPictureMode) {             // ...         } else {             if (onStopCalled) {                 finish()             }         }     } 
like image 35
Saeed Masoumi Avatar answered Sep 22 '22 15:09

Saeed Masoumi