SDL 2.0.14 error after reentering Android activity

I ported my Windows game to Android Studio and everything’s working there except when I reopen the game after opening a different application. I’m not sure what’s causing this, but looking through some of the documents, I added SDL_Event_Filter for the six cases that it said Android requires.

Some background: When I did Android development before, I never used GLSurfaceView or other draw surfaces. Some Googling revealed that Android used to clear the active GL context and would require the application to create it again. I’m creating the SDL window with SDL_WINDOW_GL. Everything displays correctly upon opening the game. It’s only when Android 11 on my Pixel 3 reopens it that I’m encountering problems.

Some questions: Do I still need to recreate the context on Android? If so, do I first need to delete the context? If so, when? The same question for SDL_Window. In terms of OpenGL and SDL, what do I need to handle on those six event cases? This was useful for understanding when the OS triggers those events, but I’m not sure how much I need to handle internally.

If I don’t do anything, Logcat outputs the following line: “call to OpenGL ES API with no current context (logged once per thread)” followed by repeating messages (probably coming from a call in my render method): “eglSwapBuffersWithDamageKHRImpl:1393 error 300d (EGL_BAD_SURFACE)”

If I delete the context first and then recreate it with SDL_GL_CreateContext(t->getSdlWindow()), I see this in Logcat: “Assertion failure at SDL_GL_CreateContext_REAL (sdl2/src/video/SDL_video.c:3517), triggered 1 time:
‘window && window->magic == &_this->window_magic’”

If I don’t delete or recreate anything and just use SDL_GL_MakeCurrent(), that returns 0 but then I get that same error message about “no current context.”

The only modification I made to SDLActivity.java was to move mContext to a weak reference.

Does anyone have experience with this? I’ll add more here if I discover anything else. Thanks for any ideas or help.