Back button not responding

The default template for Windows Phone 8 MonoGame does not respond to the back button press. On screens other than the main menu, I use the following code to navigate back to the previous screen:

        public void HandleBackKeyPress(CancelEventArgs args)
        {
            args.Cancel = true;
            ....Exit screen to show previous one....
        }

But I dont include such code in the main menu screen so to allow the app to exit, but it doesn’t. I cant figure out what is blocking its action and how to fix it.

What version of MonoGame are you using?

What version of MonoGame are you using?
3.2

That’s suprising. Do you use multiple XAML pages? MonoGame only hooks up the back button event of the page that calls this:

this.Game = XamlGame.Create("", this);

No I only use the GamePage.xaml, and it does contain the this.Game = XamlGame.Create("", this);

Here is how to replicate this issue.
1- Create a new solution from a MonoGame WP8 template. This template will be referencing MonoGame.Framework 3.0.1, and it does respond to back button.
2- Remove reference to MonoGame.Framework
3- Using package manager, install-package MonoGame.Binaries, then install-package MonoGame (yes to all replace)
4- Build and deploy, test back button, does not respond.

Any idea how to fix this? this issue is holding back my release since it wont pass review like this, and even if it did, I don’t want the players to feel like am trapping them in my app…

My recommendation is to use the github version instead of the nuget one. I’ve been working on that for a year now and it works fine.
It will allow you to debug the actual issue.

What if you remove args.Cancel = true; from your handler?

I recreated the issue as detailed in my previous post, which doesn’t include any back button handlers, and the problem still occurs.

Same issue here.

My question is: what’s the event triggered by the Back Button?

In my experience with Unity and WP8, to handle the Back button (and close the application, as example) we need to watch for the “Escape” button.

Is there any similar concept in Monogame?

In your game class you can override this

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)

to handle the back button tap. You have to set e.Cancel to true before base.OnBackKeyPress to prevent the app from exiting and instead handle it yourself. Tho it seems the app is not exiting when I dont interrupt this event or keep e to ‘true’ and thats the issue here. I semi fixed it by asking the user if he/she really wants to leave and quitting the app myself.

Ok. Here’s what I observed:

The override must be on the GamePage class, not in the Game class.
It do not exit the app, indeed. There must be a Game.Exit() call explicited for it to exit the game, and then it exits the app without problem.

I think the way you “semi fixed” is correct.

I know this is an old topic, but since I needed this information and this is the “newest” topic that contains the back button, here goes.

I was trying to get the back button to work in the Game State Management example from the old XNA site as it seems to have a pretty good screen management system.

I had created it as a Universal App for Windows/Phone 8.1 and the back button would only function as the phone back button and suspend the app.

I tried the above and nowhere would it let me override the OnBackKeyPress or hardware overrides.

To fix it I downloaded the code from github (would assume just downloading the binaries would work but wanted the code just in case) and used this for my reference.

In this version the HardwareButtons.BackPressed is permanently set to set the GamePad back button and consider the back button event as handled. So wherever you’re handling input you’ll look for the GamePad back button and do what needs to be done (whether that is navigating backwards through menus or exiting the game).

I have recently implemented back button support for Windows Phone 8.1. It’s in the develop branch on GitHub. You can handle back button like you normally would in XNA - using GamePad.

Ok, and on which namespace is located the GamePad function? I have tried out all namespaces and the gamepad function didn’t appear.

Microsoft.Xna.Framework.Input