PATCH: Improved support of background/foreground behavior for Android


#1

Using an application in portrait orientation, turning off the device would dispatch SDL_APP_WILLENTERBACKGROUND, then SDL_APP_DIDENTERBACKGROUND then lock the screen.

However, rotating the application the application to landscape, then turning off the device would incorrectly dispatch SDL_APP_WILLENTERBACKGROUND, SDL_APP_WILLENTERBACKGROUND, SDL_APP_WILLENTERFOREGROUND and then SDL_APP_DIDENTERFOREGROUND before locking the screen. You can imagine how this created trouble :slight_smile:

It appears this occurs because (on this application) turning off a device when in landscape is triggering a resize. The resize logic in SDLActivity triggers a resume.

This patch has resolved the issue on my device:

It prevents the dispatch of (improper) FOREGROUND events when locking the device, but we get still events when the device is turned back on and unlocked.

Thanks :slight_smile:


#2

This patch is now https://hg.libsdl.org/SDL/rev/8625e527f0f0, thanks!


#3

Heads up, @singmajesty:

I just backed this patch out in favor of a different one, that I think solves this problem more correctly.

The new patch is this:

Would you mind trying the latest in Mercurial and seeing if it also fixes your problem? If this patch broke it again, we’ll deal with it.

Thanks,
–ryan.