The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Issues with screen lock on android
Alexey Petruchik
Guest

Hi! I need some expert help with onPause() and screen lock handling on Android. Currently when I minimize my app by pressing home button I suspect two messages: SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERBACKGROUND after it. In real world after handling SDL_APP_WILLENTERBACKGROUND event my SDL thread forever blocks on SDL_PollEvent() call until I maximize my app. So SDL_APP_DIDENTERBACKGROUND never comes. I guess it happens because of Android_PauseSem (not sure). This is probably not a big problem because app restores fine from minimized state. Problems appear when I lock screen using hardware button. First it causes onPause() to happen which pauses SDL thread. Then onDestroy() event occurs which waits for sdl thread to quit. It seems to be a deadlock. When I try to unlock device everything freezes. So I can do anything. Only hard reboot solves helps. Looking for your help to solve this issue. Thanks.

My device is Galaxy Nexus running Android 4.2


Regads, Alexey.
Issues with screen lock on android
gabomdq


Joined: 28 Jul 2011
Posts: 495
Location: Argentina
2013/8/7 Alexey Petruchik
Quote:
Hi! I need some expert help with onPause() and screen lock handling on Android. Currently when I minimize my app by pressing home button I suspect two messages: SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERBACKGROUND after it. In real world after handling SDL_APP_WILLENTERBACKGROUND event my SDL thread forever blocks on SDL_PollEvent() call until I maximize my app. So SDL_APP_DIDENTERBACKGROUND never comes. I guess it happens because of Android_PauseSem (not sure). This is probably not a big problem because app restores fine from minimized state. Problems appear when I lock screen using hardware button. First it causes onPause() to happen which pauses SDL thread. Then onDestroy() event occurs which waits for sdl thread to quit. It seems to be a deadlock. When I try to unlock device everything freezes. So I can do anything. Only hard reboot solves helps. Looking for your help to solve this issue. Thanks.

My device is Galaxy Nexus running Android 4.2


Regads, Alexey.









This seems to be a bug, feel free to report on Bugzilla. The problem is that at some point someone added  SDL_APP_WILLENTERBACKGROUND / SDL_APP_DIDENTERBACKGROUND messaging on Android (probably to match iOS behavior), but we didn't add a provision on the event loop to not block it until that message reached the app. If you look at Android_PumpEvents, you'll see a "if (SDL_HasEvent(SDL_WINDOWEVENT))" that prevents the loop from blocking until the window minimized messages reach the app. I think something of the same sort will need to be added there for these new messages.



--
Gabriel.