Santosh Santosh - 8 months ago 86
Android Question

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?


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)
            return true;
        if (!UrhoSurface.DispatchKeyEvent(e))
            return false;
        return base.DispatchKeyEvent(e);