Resuming after exiting calls draw once then quits, saying Surface Destroyed

I’m trying to port an old XNA Windows Phone game to Android using Monogame. So far it’s been very straight forward and I was able to get it up and running very quickly.

The main issue I’m having has to do with resuming the app. When it resumes after an exit call, it calls draw once and then quits again.

I’m using MonoGame.Framework version 3.6.0.1625. I did change to using the monogame content pipeline.

I use Game.Exit() to quit the game like I did in XNA on Windows Phone. If the user then resumes it from the open app list, it just calls draw once then quits. During that draw call the game object has the private variable _shouldExit = true, which seems to be a likely cause, but I am not sure why it is in that state. I’ve seen some people suggest using Game.Activity.MoveTaskToBack(true); instead, but that seems to behave exactly the same. The console output as the resume and quit happens shows this:

01-30 20:07:06.528 E/EGL_emulation( 1536): [getAttribValue] Bad attribute idx 01-30 20:07:06.528 E/EGL_emulation( 1536): tid 1536: eglGetConfigAttrib(605): error 0x3004 (EGL_BAD_ATTRIBUTE) 01-30 20:07:06.532 D/MonoGame( 1536): MonoGameAndroidGameView.SurfaceCreated: surfaceFrame = Rect(0, 0 - 1080, 1788) 01-30 20:07:06.532 D/MonoGame( 1536): GraphicsDeviceManager.ResetClientBounds: newClientBounds={X:0 Y:0 Width:1080 Height:1788} 01-30 20:07:06.532 D/MonoGame( 1536): MonoGameAndroidGameView.SurfaceChanged: format = Rgb565, width = 1080, height = 1788 01-30 20:07:06.536 D/MonoGame( 1536): GraphicsDeviceManager.ResetClientBounds: newClientBounds={X:0 Y:0 Width:1080 Height:1788} 01-30 20:07:06.696 D/MonoGame( 1536): MonoGameAndroidGameView.SurfaceDestroyed

If I run it on a phone instead of the emulator, it does the exact same thing, but the console output is:

01-30 20:17:12.310 V/InputMethodManager( 4331): Starting input: tba=android.view.inputmethod.EditorInfo@c36cff7 nm : TilesMonoAndroid.TilesMonoAndroid ic=null 01-30 20:17:12.310 I/InputMethodManager( 4331): startInputInner - mService.startInputOrWindowGainedFocus 01-30 20:17:12.437 D/ViewRootImpl@676c93b[Activity1]( 4331): MSG_WINDOW_FOCUS_CHANGED 0 01-30 20:17:12.438 I/AudioTrack( 4331): Skip ramp 01-30 20:17:12.442 D/SensorManager( 4331): unregisterListener :: 01-30 20:17:12.474 D/SurfaceView( 4331): Relayout returned: oldFrame=[0,0][720,1280] newFrame=[0,0][720,1280] result=0x5 surface={Surface(name=null)/@0x37ebe17 isValid=false 0} 01-30 20:17:12.480 D/MonoGame( 4331): MonoGameAndroidGameView.SurfaceDestroyed 01-30 20:17:12.510 D/ViewRootImpl@676c93b[Activity1]( 4331): Relayout returned: oldFrame=[0,0][720,1280] newFrame=[0,0][720,1280] result=0x5 surface={isValid=false 0} surfaceGenerationChanged=true 01-30 20:17:12.544 D/ViewRootImpl@676c93b[Activity1]( 4331): Relayout returned: oldFrame=[0,0][720,1280] newFrame=[0,0][720,1280] result=0x1 surface={isValid=false 0} surfaceGenerationChanged=false

Emulator version is targetting Android 4.4 - API 19. The test phone is Android 7.1 - API 25.

Anyone have any suggestions of what I should look into that could be causing it to fail? Thanks for your help.

Hi - I have exactly the same problem.
The problem even occurs on a completely clean app generetated from the Visual Studio template.

For now I getting round the problem by calling Finish on the Game’s parent activity instead of Game.Exit() and then rebuilding the activity (and Game) when the app comes back in the foreground. Not ideal.