Has anyone got any experience or advice on managing back stack and tasks in PiP mode for android O?
Entering PiP mode seems to detach the activity from the current task stack. And exiting doesn't restore it.
Chrome seems to handle the back stack correctly when using PiP in that you enter pip mode, can navigate around other apps, restore pip to full screen and press back to end up back in the web page. You also don't see Chrome in the task list whilst it's in PiP mode. Is there something I'm missing or is Chrome doing something special or possibly only using a single activity for a Tab and full screen video?
Basically I want restore the entire app and it's back stack at the point we entered PiP when coming back from PiP.
Picture-in-picture (PiP) shrinks a video into a small player so you can keep watching while using other apps on your mobile device. You can move the small player around your device's home screen and position it over other apps.
A task is a collection of activities that users interact with when trying to do something in your app. These activities are arranged in a stack—the back stack—in the order in which each activity is opened. For example, an email app might have one activity to show a list of new messages.
PiP is a special type of multi-window mode mostly used for video playback. It lets the user watch a video in a small window pinned to a corner of the screen while navigating between apps or browsing content on the main screen.
Unfortunately, none of the Google apps (YouTube, Duo, Chrome) have this issue because they tend to use only a single Activity, and so when entering or leaving PiP there is no task issue in the recents menu because there is only ever a single task with a single Activity in it. This is why you do not see any entry in the recents menu for these apps when they are in PiP mode; it is being hidden by the APIs.
If you use multiple Activities in your app, then you will run into this issue. This is especially common given that most apps out there will use a new Activity in the task that launched their application to house their video playback.
The best solution I have found is to make your video player Activity be in its own task (set a unique task affinity) and hide it from the recents menu. This results in expected behaviour when entering and exiting PiP as well as allowing the user to navigate throughout the rest of your app (via the other tasks) without interfering with the PiP task. Unfortunately, this means that users will not be able to re-enter your video player from the recents; if the users uses the home or recents buttons, the video player task will end up being destroyed and your player Activity will be finished.
<activity
android:name=".YourVideoPlayerActivity"
android:resizeableActivity="true"
android:configChanges="keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation"
android:supportsPictureInPicture="true"
android:launchMode="singleTask"
android:taskAffinity=".YourVideoPlayerActivityTask"
android:excludeFromRecents="true"
android:noHistory="true"
android:autoRemoveFromRecents="true" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With