MonoGame Android App Not Resuming

I just installed MonoGame 3.7.1 and created a brand new out-of-the-box boilerplate app for Android. It runs - just a blue screen - but when I exit the app with the back arrow and then try to resume it, it just flashes for an instant, and then closes again. Meaning: it cannot resume. Meanwhile every time I try to resume it, this is what it logs to the debug output:

07-02 20:31:39.984 D/ViewRootImpl@da8bb5cActivity1: mHardwareRenderer.destroy()#1
07-02 20:31:39.992 D/ViewRootImpl@da8bb5cActivity1: Relayout returned: oldFrame=[0,0][720,1280] newFrame=[0,0][720,1280] result=0x1 surface={isValid=false 0} surfaceGenerationChanged=false
07-02 20:31:40.008 D/SensorManager(26166): registerListener :: 0, 66667, 0,
07-02 20:31:40.029 D/SurfaceView(26166): Relayout returned: oldFrame=[0,0][720,1280] newFrame=[0,0][720,1280] result=0x7 surface={Surface(name=null)/@0x6fe473a isValid=true -2030430208}
07-02 20:31:40.054 D/ViewRootImpl@da8bb5cActivity1: Relayout returned: oldFrame=[0,0][720,1280] newFrame=[0,0][720,1280] result=0x7 surface={isValid=true -2028197888} surfaceGenerationChanged=true
07-02 20:31:40.054 D/ViewRootImpl@da8bb5cActivity1: mHardwareRenderer.initialize() mSurface={isValid=true -2028197888} hwInitialized=true
07-02 20:31:40.062 D/MonoGame(26166): GraphicsDeviceManager.ResetClientBounds: newClientBounds={X:0 Y:40 Width:720 Height:1200}
07-02 20:31:40.064 D/ViewRootImpl@da8bb5cActivity1: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 720, 1280) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 48 - 0, 0) or=1
07-02 20:31:40.064 D/ViewRootImpl@da8bb5cActivity1: MSG_WINDOW_FOCUS_CHANGED 1
07-02 20:31:40.065 D/ViewRootImpl@da8bb5cActivity1: mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true -2028197888}
07-02 20:31:40.065 V/InputMethodManager(26166): Starting input: tba=android.view.inputmethod.EditorInfo@72c43ea nm : BlindFindAndroid.BlindFindAndroid ic=null
07-02 20:31:40.065 I/InputMethodManager(26166): startInputInner - mService.startInputOrWindowGainedFocus
07-02 20:31:40.069 D/InputTransport(26166): Input channel constructed: fd=71
07-02 20:31:40.213 D/ViewRootImpl@da8bb5cActivity1: MSG_RESIZED: frame=Rect(0, 0 - 720, 1280) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
07-02 20:31:40.218 D/SensorManager(26166): unregisterListener ::
07-02 20:31:40.226 I/AudioTrack(26166): Skip ramp
07-02 20:31:40.257 D/SurfaceView(26166): Relayout returned: oldFrame=[0,0][720,1280] newFrame=[0,0][720,1280] result=0x5 surface={Surface(name=null)/@0x6fe473a isValid=false 0}
07-02 20:31:40.317 D/ViewRootImpl@da8bb5cActivity1: mHardwareRenderer.destroy()#1
07-02 20:31:40.345 D/ViewRootImpl@da8bb5cActivity1: Relayout returned: oldFrame=[0,0][720,1280] newFrame=[0,0][720,1280] result=0x5 surface={isValid=false 0} surfaceGenerationChanged=true
07-02 20:31:40.347 D/ViewRootImpl@da8bb5cActivity1: MSG_WINDOW_FOCUS_CHANGED 0
07-02 20:31:40.374 D/InputTransport(26166): Input channel destroyed: fd=71

Why is this? How do I fix this?

I’ve been wondering about this too. The only fix I’ve been able to come up with is to disable minimizing the game with the back button… remove the Exit() call from the Update method, and override Activity.OnBackPressed and stub it out.
Not a great solution, but the only thing I’ve been able to come up with that doesn’t break the app :confused:

I have done this by adding flag:

bool _exit = false;

update:

  if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
      HandleBackButton();

  if (_exit)
  {
      _exit = false;
      Game.Activity.MoveTaskToBack(true);
  }

and

void HandleBackButton()
{
    _exit = true;
}
3 Likes

Thanks, this actually solved the problem!
@tunkio @dmanning23 A question: don’t you guys think we should report this as a bug? I mean it really ruins the experience for MonoGame, especially for newcomers because it may scare them away.

Absolutely report it as a bug! You can file an issue on the official GitHub repository here.

OK, I reported it, let’s hope it will be fixed. https://github.com/MonoGame/MonoGame/issues/6804