1

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

Horo
  • 11
  • 2

1 Answers1

4

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.

caligari
  • 2,110
  • 20
  • 25
  • Cool, thx for help. It is not an integrated solutions as event driven, while ExEn uses XNA game loop poll logic for input, but with a minimal hack it can be used. Thx again. – Horo Oct 07 '11 at 16:45