detect back button pressed?

Monkey Targets Forums/Android/detect back button pressed?

slenkar(Posted 2013) [#1]
has anyone written code to detect if the user presses the back button?

(the arrow facing left, not the home button)


c.k.(Posted 2013) [#2]
During OnUpdate(), do this:

[monkeycode]
If KeyHit(KEY_ESCAPE) Then
' back arrow was hit
EndIf
[/monkeycode]


slenkar(Posted 2013) [#3]
thanks


benmc(Posted 2013) [#4]
It should be noted that the back button on Windows phone will only respond to JoyHit( JOY_BACK ) so I tend to use both.


Supertino(Posted 2013) [#5]

If KeyHit(KEY_ESCAPE) Then
' back arrow was hit
EndIf



on 4.1/4.2 sleeps the app it seems and returns the user to the home screen as if they pressed the home button, happens on a Nexus 7 (4.2) and S3mini (4.1), doesn't matter what I do inside the IF.


Supertino(Posted 2013) [#6]
oh wait there is the new OnClose and OnBack stuff. I'll look at that


Xaron(Posted 2013) [#7]
Yes, using onBack works great now!


sandfella(Posted 2013) [#8]
So, there's also ExitApp which is called by default when OnBack is called.

So new to monkey... so how would you override the code. Would something like this work?
if (OnBack()) 
   // do my stuff
   ExitApp

....

function OnBack:void()
   // add code to ask user if he really wants to quit...
   ExitApp


(and I'm using V69, waiting for V70 release.. :))