How to check if the Activity is visible? onResume is not enough
android, android-activity, android-lifecycle
Solution
You need to wait for the onWindowFocusChanged event as well as the OnResume event. It's a well known issue that no longer occurs in Android 4.1+. Details are available at http://android-developers.blogspot.co.uk/2011/11/making-android-games-that-play-nice.html
Problem
One of my activity embeds `VideoView` to play some content. I implemented pausing/resuming the video in `onPause()` and `onResume()`, respectively, but to my surprise - `onResume` is called before the activity is really visible to the user. To be exact, the scenario is as follows: - activity is on screen, video is playing - user locks the phone with power button - activity gets `onPause()` called, video stops - user presses power button - activity gets `onResume()` called (and thus resumes video) before the user unlocks the screen I confirmed this behaviot with Android 2.2, 2.3 and 4.0. I guess it is intentionally done like that, to let the activity prepare to redraw itself immediately after locking screen goes away. How can I detect the moment when the activity actually appears to the user? I've tried to wait for `onWindowFocusChanged(true)` being called, and it seems to work, but it doesn't make me feel perfectly safe.