Task List and Back Stack with Android O Picture in Picture mode
Asked Answered
A

1

18

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.

Appellate answered 19/7, 2017 at 10:33 Comment(1)
I have a same question here have you got any of solution about this problem.Laflam
E
20

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" />
Ectoenzyme answered 12/9, 2017 at 14:57 Comment(2)
I am having similar activity parameters in the manifest. But still, see the new activity in the recents app as a new task. PS I am not using noHistory attribute due to some limitations.Dulse
Thanks, android:taskAffinity and android:excludeFromRecents did the job for me.Virulence

© 2022 - 2024 — McMap. All rights reserved.