Search code examples
androidonresume

Activity life-cycle / media resumes playing on the lock-screen


I'm working on a media streaming app, and noticing some odd behavior. Media stops playing when my device locks, but then starts playing again before I even unlock the device.

Any suggestions what might cause this?


Solution

  • This is due to the way the Android lifecycle works when you hit the unlock button but are still on the lock screen.

    onResume() doesn’t necessarily mean your app is visible — only that it’s active. In the case of a locked phone, onResume() is sent as soon as the screen turns on, even though the phone’s display is on the lock screen.

    This is detailed in this blog post:

    http://android-developers.blogspot.com/2011/11/making-android-games-that-play-nice.html