androidxamarinurhosharp

Back Button not Responding in UrhoSharp


I have create an Activity which has a UrhoSharp surface as;

SDLSurface surface = UrhoSurface.CreateSurface(this, typeof(UrhoLayer), appOptions);

Now back button is not Responding. I tried overriding onBackPressed(), but this function is not called when I press back button. How to make the back button work?


Solution

  • I resolved this by catching the back button press in DispatchKeyEvent. Not a very satisfactory solution, but it works:

        public override bool DispatchKeyEvent(KeyEvent e)
        {
            if (e.Action == KeyEventActions.Up && e.KeyCode == Keycode.Back)
            {
                OnBackPressed();
                return true;
            }
            if (!UrhoSurface.DispatchKeyEvent(e))
                return false;
            return base.DispatchKeyEvent(e);
        }