Android: more about pause and resume

Hi,

This morning I read in the newspaper that 75% of all phones and tablets are running Android. Also I know that Pelya’s SDL port for Android gets an huge amount of weekly downloads. So, although I know that Sam is busy with the Android part of SDL right now, I still want to ask a question about the humble subject of pause and resume.

In a normal Android app the onPause() and onResume() callbacks are very important, because they are all you need to enable gentle starting, restoring and stopping of your app. In SDLActivity.java exactly these callbacks are commented out, because they are needed elsewhere. So I did a little research to investigate what events I get when I touch the back- and the home key of an Android tablet.

The home (soft) key should generate 2 window events: SDL_WINDOWEVENT_FOCUS_LOST and SDL_WINDOWEVENT_MINIMIZED. However, no events at all appear. You get them when you restart the app from the home screen, followed by SDL_WINDOWEVENT_FOCUS_GAINED and SDL_WINDOWEVENT_RESTORED. This last event is the only one you need, it indicates that you have to redraw the screen.

The back (soft) key generates a SDL_KEYDOWN event with a SDL_Keysym.sym value KMOD_MODE. This is the only result, your app is not affected at all. It would be nice if the app launching-screen would be invoked, which is what the user is expecting. I could not find any way to enforce this using SDL code.

Maybe all this is inevitable? SDL must be shoehorned into very different environments, so clashes are to be expected. Must I learn to live with them, or will the Android part be further developed and documented, accompanied by good example code?

wboe

Nope, SDL should be a good citizen in whatever environment it’s in. Feel
free to make any changes you think are appropriate and since SDL 2.0 is
zlib license, have fun with it!

Anything that you think would be generally useful, feel free to add back to
bugzilla.libsdl.org and post on the list about.

Thanks!On Thu, Nov 8, 2012 at 7:30 AM, wboe <w.boeke at upcmail.nl> wrote:

**
Hi,

This morning I read in the newspaper that 75% of all phones and tablets
are running Android. Also I know that Pelya’s SDL port for Android gets an
huge amount of weekly downloads. So, although I know that Sam is busy with
the Android part of SDL right now, I still want to ask a question about the
humble subject of pause and resume.

In a normal Android app the onPause() and onResume() callbacks are very
important, because they are all you need to enable gentle starting,
restoring and stopping of your app. In SDLActivity.java exactly these
callbacks are commented out, because they are needed elsewhere. So I did a
little research to investigate what events I get when I touch the back- and
the home key of an Android tablet.

The home (soft) key should generate 2 window events:
SDL_WINDOWEVENT_FOCUS_LOST and SDL_WINDOWEVENT_MINIMIZED. However, no
events at all appear. You get them when you restart the app from the home
screen, followed by SDL_WINDOWEVENT_FOCUS_GAINED and
SDL_WINDOWEVENT_RESTORED. This last event is the only one you need, it
indicates that you have to redraw the screen.

The back (soft) key generates a SDL_KEYDOWN event with a SDL_Keysym.sym
value KMOD_MODE. This is the only result, your app is not affected at all.
It would be nice if the app launching-screen would be invoked, which is
what the user is expecting. I could not find any way to enforce this using
SDL code.

Maybe all this is inevitable? SDL must be shoehorned into very different
environments, so clashes are to be expected. Must I learn to live with
them, or will the Android part be further developed and documented,
accompanied by good example code?

wboe


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

In a normal Android app the onPause() and onResume() callbacks are very

important, because they are all you need to enable gentle starting,
restoring and stopping of your app. In SDLActivity.java exactly these
callbacks are commented out, because they are needed elsewhere. So I did a
little research to investigate what events I get when I touch the back- and
the home key of an Android tablet.

These calls happen on the Java thread, they need to be “routed” to the SDL
thread, which is why we send events to let the user know the app has been
"minimized" and “restored”

The home (soft) key should generate 2 window events:
SDL_WINDOWEVENT_FOCUS_LOST and SDL_WINDOWEVENT_MINIMIZED. However, no
events at all appear. You get them when you restart the app from the home
screen, followed by SDL_WINDOWEVENT_FOCUS_GAINED and
SDL_WINDOWEVENT_RESTORED. This last event is the only one you need, it
indicates that you have to redraw the screen.

If you are using BLOCK_ON_PAUSE, you should be
getting SDL_WINDOWEVENT_FOCUS_LOST and SDL_WINDOWEVENT_MINIMIZED before
the loop pauses. See here:
http://hg.libsdl.org/SDL/file/018f8019ce36/src/video/android/SDL_androidevents.c
There’s a provision not to block the loop until after all events of
type==SDL_WINDOWEVENT are processed, precisely to avoid pausing without
letting the app know what’s gonna happen. If this is not happening with the
current SDL from HG, feel free to create a bug report for it.

The back (soft) key generates a SDL_KEYDOWN event with a SDL_Keysym.sym
value KMOD_MODE. This is the only result, your app is not affected at all.
It would be nice if the app launching-screen would be invoked, which is
what the user is expecting. I could not find any way to enforce this using
SDL code.

I think this is outside of what SDL should provide, it’s debatable though.–
Gabriel.

Hi,

This morning I read in the newspaper that 75% of all phones and tablets are running Android. Also I know that Pelya’s SDL port for Android gets an huge amount of weekly downloads. So, although I know that Sam is busy with the Android part of SDL right now, I still want to ask a question about the humble subject of pause and resume.

In a normal Android app the onPause() and onResume() callbacks are very important, because they are all you need to enable gentle starting, restoring and stopping of your app. In SDLActivity.java exactly these callbacks are commented out, because they are needed elsewhere. So I did a little research to investigate what events I get when I touch the back- and the home key of an Android tablet.

If you want to handle such events in an universal way on various
devices/OSes like iOS, Android, Win8/Win RT, check out the handler for
such events here: http://www.union.org.pl/download/sdl/
The one located here is quite old and supports only iOs and Android.

regards,
PiotrOn Thu, 8 Nov 2012, wboe wrote: