How to Handle Android hardware backbutton in ExEn?

2k views Asked by At

I am using Mono for Android and ExEn (thx for Andrew Russell). I am not sure this question is specific to Mono for Android or more specific to ExEn. Anyway, I found only Java samples as a result of my searches.

I would like to implement a standard game menu navigation using the hardware back button. Currently back button exits the application regardless the state of the gameplay or menu.

Thx for answers. -Horo

1

There are 1 answers

1
caligari On

It is an Android specific question and you must override OnKeyDown method on your activity. Coding in Mono for Android:

public override bool OnKeyDown(Keycode keyCode, KeyEvent e)
{
  if (keyCode == Keycode.Back)
  {
    // your staff here:
    Toast.MakeText(this, "back!", ToastLength.Short).Show();

    return true;
  }

  return base.OnKeyDown(keyCode, e);
}

Remember to return "true" after your code to indicate you have handled the event.