diff -r 321d66a4841a src/core/android/SDL_android.cpp --- a/src/core/android/SDL_android.cpp vie may 25 16:23:29 2012 -0300 +++ b/src/core/android/SDL_android.cpp vie jun 01 19:03:51 2012 -0300 @@ -176,6 +176,7 @@ JNIEnv* env, jclass cls) { if (Android_Window) { + Android_WindowHidden = 1; SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); } diff -r 321d66a4841a src/video/android/SDL_androidevents.c --- a/src/video/android/SDL_androidevents.c vie may 25 16:23:29 2012 -0300 +++ b/src/video/android/SDL_androidevents.c vie jun 01 19:03:51 2012 -0300 @@ -23,11 +23,41 @@ #if SDL_VIDEO_DRIVER_ANDROID #include "SDL_androidevents.h" +#include + +/* Defined to have the same value as in SDL_events.c */ +#define MAXEVENTS 128 void Android_PumpEvents(_THIS) { /* No polling necessary */ + + static SDL_Event events[MAXEVENTS]; + SDL_WindowEvent *event; + int numevents = 0, i; + + /* Android_WindowHidden is set to 1 in Java_org_libsdl_app_SDLActivity_nativePause */ + if(Android_WindowHidden) { + if (Android_Window){ + numevents = SDL_PeepEvents(events, MAXEVENTS, SDL_PEEKEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT); + SDL_assert(numevents < MAXEVENTS); + for (i=0;ievent == SDL_WINDOWEVENT_RESTORED) { + /* SDL_GL_CreateContext will end up in SDLActivity.java -> initEGL -> createEGLSurface + * createEGLSurface will try first to restore the current GL context and if that fails it'll call createEGLContext + * if that happens, you have to reload your textures! + * TODO: Should we double check if we are on the same thread that originally created the GL context? + * TODO: Send the user a message to let him know that the GL context has changed behind the scenes + */ + SDL_GL_CreateContext(Android_Window); + Android_WindowHidden = 0; + break; + } + } + } + } } #endif /* SDL_VIDEO_DRIVER_ANDROID */ diff -r 321d66a4841a src/video/android/SDL_androidevents.h --- a/src/video/android/SDL_androidevents.h vie may 25 16:23:29 2012 -0300 +++ b/src/video/android/SDL_androidevents.h vie jun 01 19:03:51 2012 -0300 @@ -21,6 +21,8 @@ #include "SDL_config.h" #include "SDL_androidvideo.h" +#include "SDL_events.h" +#include "SDL_assert.h" extern void Android_PumpEvents(_THIS); diff -r 321d66a4841a src/video/android/SDL_androidvideo.c --- a/src/video/android/SDL_androidvideo.c vie may 25 16:23:29 2012 -0300 +++ b/src/video/android/SDL_androidvideo.c vie jun 01 19:03:51 2012 -0300 @@ -64,6 +64,7 @@ int Android_ScreenWidth = 0; int Android_ScreenHeight = 0; Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN; +int Android_WindowHidden = 0; /* Currently only one window */ SDL_Window *Android_Window = NULL; diff -r 321d66a4841a src/video/android/SDL_androidvideo.h --- a/src/video/android/SDL_androidvideo.h vie may 25 16:23:29 2012 -0300 +++ b/src/video/android/SDL_androidvideo.h vie jun 01 19:03:51 2012 -0300 @@ -33,8 +33,10 @@ extern int Android_ScreenWidth; extern int Android_ScreenHeight; extern Uint32 Android_ScreenFormat; +extern int Android_WindowHidden; extern SDL_Window *Android_Window; + #endif /* _SDL_androidvideo_h */ /* vi: set ts=4 sw=4 expandtab: */ diff -r 321d66a4841a src/video/android/SDL_androidwindow.c --- a/src/video/android/SDL_androidwindow.c vie may 25 16:23:29 2012 -0300 +++ b/src/video/android/SDL_androidwindow.c vie jun 01 19:03:51 2012 -0300 @@ -35,6 +35,7 @@ return -1; } Android_Window = window; + Android_WindowHidden = 0; /* Adjust the window data to match the screen */ window->x = 0;