Table of Contents

Can't use the phone's menu button?

Things are not quite as straightforward with android menu buttons as they used to be.

How it used to work

Each android phone came with a menu button.

When the user pressed it, the appropriate menu was displayed.

app.SetMenu is supplied to define the appropriate menu(s) in your app.

But my phone/tablet has no menu button

Unfortunately, it is becoming much more common for devices not to provide a menu button.

How to show the menu anyway

app.ShowMenu() can be used from your code to display the menu.
The most appropriate way to call this is usually from a button.

However, if you are very short of screen space, it may be easier to hijack the device's Back Button instead.

If you do this, don't forget to leave a way to exit the app.

Some sample code is included here to show a way to do this.

Sample code

backButtonMenu.js
//Called when application is created.  
function OnStart()
{     
    app.SetMenu( "Exit,Model,Display" );  
    app.EnableBackKey( false );  
    app.ShowPopup ( "Back key emulates Menu key" ); 
}  
 
//Called when user selects a menu item.  
function OnMenu( name )
{           
    if ( name == "Exit" ) app.Exit() ; 
    if ( name == "Model" ) app.ShowPopup( app.GetModel() ); 
    if ( name == "Display" ) 
    {
        var s = app.GetDisplayWidth() + " x " + app.GetDisplayHeight();
        app.ShowPopup( s );
    }
}  
 
//Called when the back key is pressed.  
function OnBack()
{ 
  app.ShowMenu(); 
}