Activity onStop() not called when home button is pressed in Android N multi window mode
Asked Answered
A

2

10

I am trying to make our video app to support Android N multiwindow mode. I have discovered that activity lifecycle becomes confused in multiwindow mode. The phenomenon is when our app layouts on the top screen with the whole screen in portrait, then I click the Home button, the upper app onPause() called but onStop() not called.

According to the google guideline https://developer.android.com/guide/topics/ui/multi-window.html#lifecycle, video app should pause video playback in onStop() callback rather than onPause() callback.

In this situation, home button is pressed, the activity go background and become not visible to user, our app should pause video playback but we cannot get onStop() callback. Meanwhile, the activity do not fire onMultiWindowChanged() callback, this means the activity is still in multiwindow mode though it is in background. The isInMultiWindowMode() will return true in this case.

The same issue will occur when the app is in the left screen with the whole screen in landscape.

I have searched for this question and find someone has alreay post issues to google but not handled in the Android Nougat release.

https://code.google.com/p/android/issues/detail?id=215650&can=1&q=multi%20window%20onstop&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened

So, when is the right time to pause our video playback in such situation? If we pause the video in the onPause() callback, but the activity may be visible to user in multiwindow mode. If we not do, we cannot get the onStop() callback in this case. Are there some proper workaround for such cases?

Alternant answered 28/9, 2016 at 3:54 Comment(0)
A
2

When you hit the home button in multi-window mode, the system is in a transient state, allowing the user to select an app to start while your app continues to run (if you're the topmost app, you'll note you can still see the status bar from your app). There is no callback associated with going into this transient mode and you should not change your behavior when entering this transient mode.

Instead, you should continue to play any video - only stop your video when you receive a callback to onStop().

Adenocarcinoma answered 28/9, 2016 at 4:27 Comment(7)
(I know, it feels weird, but it is supposed to be a mode that users are in only briefly)Adenocarcinoma
when I click the bottom of app and make it become the topmost app and then press the home button, I see the status bar still from the top of app and the onStop() of top app also not called. Though the case may be a transient state, but we cannot assure user pick up another app soon. The several seconds is important for a video appAlternant
There's no way to tell when this state occurs, so you really don't have any choice.Adenocarcinoma
@zjupure: I filed a feature request to have some sort of API to let us know when we are in this state. I agree with you that continuing to play the video indefinitely is not a good plan. I am even more concerned with the full wakelock that many apps use (e.g., setKeepScreenOn(true)); if the user presses HOME and walks away, we need to know that we need to release that wakelock.Kahl
@Adenocarcinoma in some apps like 'soccer stars' this problem doesn't exist. what do they do?!Botfly
@Adenocarcinoma I check the visibility percentage of a view(like 50% of view is visible) using view.getGlobalVisibleRect(Rect). But in the transient mode, even when no Views are visible, using the above function for a View(which was 100% visible in multi-window mode ) returns the same result. Is there any way i can determine that the View is 0% visible because the app is in transient state?Golightly
@Golightly - no, there's no API for detecting this state.Adenocarcinoma
I
1

As per the official document MultiWinodw LifeCycle :

"Multi-window mode does not change the activity lifecycle."

In MultiWindow mode, the only activity which user has interacted most recently will be the top most activity and other activity will go into onPause() mode as it would be partially visible. When user will try to interact other activity that would go into onResume() state and it would become topmost activity and rest one would go into onPause() mode.

Now in case of music player, they have clearly mentioned that you should continue playing your music even if onPause() method will be called if you are supporting MultiWindow mode.

Only stop your video when you onStop() would be called.

Interdisciplinary answered 28/9, 2016 at 4:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.