Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 599
Graham Avatar asked Dec 23 '11 18:12

Graham


2 Answers

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

like image 161
Shams Shafiq Avatar answered Oct 14 '22 09:10

Shams Shafiq


The ciclelife of the media class do that automatically. Try @override on OnResume and OnPause methods.

like image 44
vgonisanz Avatar answered Oct 14 '22 08:10

vgonisanz