Android Tutorial Keep app from closing on back key press

I have an app that opens web pages from a menu. Having trouble getting it to NOT close every time you click the android back button (drops out of app).

Tried this code:

Sub activity_KeyPress (KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
WebView1.Visible = False
ListView1.Visible = True
End If

End Sub


Does not work, (listview1 is my main menu I want it to come back to) app still closes if you click the android back button. Does it have to go in some place special?
 

Penko

Active Member
Licensed User
Longtime User
You have to Return True in order to consume the event and thus keep the app running.

For further reference check the official guide(written by Klaus): http://www.b4x.com/android/files/guide.zip
You will find an example of exactly what you are looking for at the bottom of page 134.
 
Last edited:

GeorgeJ

New Member
Licensed User
Longtime User
This is mentioned on pages 237 (16.1) and 308 (19.6) in the guide I have. I am currently studying this very helpful guide.
 

pelican2

Member
Licensed User
Longtime User
I can't find the code in the docs contained in the link... I also have a need / desire to disable the BACK button...

It appears the beginner's guide was updated 5/18/2013 to version 2.5... after these forum posts were created. A PDF search for keywords BACK BUTTON revealed no such code...:sign0085:
 
Top