Issues with screen lock on android

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.

2013/8/7 Alexey Petruchik

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.