UrhoSamples2019 icon indicating copy to clipboard operation
UrhoSamples2019 copied to clipboard

Android BackButton Press Crashes UrhoSharp SamplyGame [Fixed]

Open iBeta666 opened this issue 2 years ago • 0 comments

I had modelled my game on SamplyGame, so was also getting hanging when pressing the Android Back Button. To fix, in MainActivity:

   public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
    {
        if (keyCode == Keycode.Back)
        {               
            this.MoveTaskToBack(false);//causes app to go to back, and works when refocussed.
            return false; //this prevents OnBackPressed(), call.                            
        }
        return base.OnKeyDown(keyCode, e);
    }

Then, delete the Esc key condition in SamplyGame, as shown:

SamplyGame.Start() { Input.SubscribeToKeyDown(e => { if (e.Key == Key.Esc) Exit();//<- this causes app crash/hang } }

The app is now sent to the background, and opens nicely when refocussed.

iBeta666 avatar Dec 18 '22 12:12 iBeta666