Resume Android App running in the background

Just tested can’t resume after Exit(); using backbutton (monogame 3.8.0.1641).

Cloned monogame source and find this, in AndroidGameActivity.cs

protected override void OnPause()
{
       base.OnPause();
       //EventHelpers.Raise(this, Paused, EventArgs.Empty);

        if (_orientationListener.CanDetectOrientation())
             _orientationListener.Disable();
}

If that EventHelpers.Raise is commented out, I can resume after Exit() via backbutton…

1 Like

Trying this out now myself…

So since I don’t use the source normally. Clone, Build, Build Tools, Create Android App with template, delete nuget refs, Add projects as references to the Android project are the steps right?

Ok trying out right now…

Works for me too on the emulator so far…

Now testing on a device…

Worked on the device too.

@tunkio Good work! I marked this as Solution! :slight_smile:
@Trinith Good workaround! I leave it here too for others using the current version provided by the nugets.

1 Like

I reported issue to github Android not resuming to app after using Exit(); via backbutton · Issue #7458 · MonoGame/MonoGame · GitHub

Created a pull request here which applies the change described by @tunkio which fixes the issue but probably it needs more work because the commented source may be necessary for other platforms or something which I don’t know and did not check at this point. Further discussion can be done on GitHub of course.

Can you try something else?

Revert back to the original source code and then add the following line inside LoadContent() or in your Game1 Constructor.

‘SoundEffect.Initialize();’

an alternative is to try and load a soundEffect from the Content.

then try to see if the app still fails to resume.

Tried all that you suggested, not resuming

1 Like

Thanks anyway for the try.

I assumed there is something in the activity_pause() method that fails. probably is something else …

Instead of calling Exit(), use MoveTaskToBack(true) inside the Update method.
Also I have the following code in all my AndroidGameActivity objects, I think this was to bypass whatever internal flag that causes this behavior:

/// <summary>
/// Overide the default back button behavior, and do nothing
/// </summary>
public override void OnBackPressed()
{
}

I used that in 3.7, but no success on 3.8…