Stopping the user using Back Button

Shane119

Member
Licensed User
Longtime User
Hi Everyone

Is there a way of stopping the user from closing an activity by pressing the back button. I want the activity to remain active (unless the home button is pressed) until the user selects Save or Cancel at the bottom of the activity.

Thanks again in advance for you help, I'm really starting to get my head around the software now :sign0060:
 

canalrun

Well-Known Member
Licensed User
Longtime User
Hi Everyone

Is there a way of stopping the user from closing an activity by pressing the back button.

Here is some code that I found in another post on this site.

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean  ' Return true to consume the event
  If KeyCode = 4 Then  ' Back button
     ' -- do something here --
     Return True  ' Consume event, so the app does not close
  Else
      Return False ' Do not consume, the app will close or go to previous activity
  End If
End Sub
This code intercepts the keys and lets you perform an action or let the operating system to what it wants.

Barry.
 
Upvote 0
Top