Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixel devices do not call onPause() or onStop() when user clicks on recent-apps drawer #7

Open
liweiyap opened this issue Aug 17, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@liweiyap
Copy link
Owner

liweiyap commented Aug 17, 2024

Possible solution is to use onWindowFocusChanged() to pause/play audio players but I'm not sure how such a change would affect non-Pixel devices.


From: https://developer.android.com/reference/android/app/Activity#onWindowFocusChanged%28boolean%29

Provides information about global focus state, which is managed independently of activity lifecycle. As such, while focus changes will generally have some relation to lifecycle changes (an activity that is stopped will not generally get window focus), you should not rely on any particular order between the callbacks here and those in the other lifecycle methods such as onResume().

As a general rule, however, a foreground activity will have window focus... unless it has displayed other dialogs or popups that take input focus, in which case the activity itself will not have focus when the other windows have it. Likewise, the system may display system-level windows (such as the status bar notification panel or a system alert) which will temporarily take window input focus without pausing the foreground activity.

Starting with Build.VERSION_CODES.Q there can be multiple resumed activities at the same time in multi-window mode, so resumed state does not guarantee window focus even if there are no overlays above.

If the intent is to know when an activity is the topmost active, the one the user interacted with last among all activities but not including non-activity windows like dialogs and popups, then onTopResumedActivityChanged(boolean) should be used. On platform versions prior to Build.VERSION_CODES.Q, onResume() is the best indicator.

@liweiyap liweiyap added the enhancement New feature or request label Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant