Help with the back button Please !

dealsmonkey

Active Member
Licensed User
Longtime User
Ok, this is driving me nuts !!

I have my app main screen loading as a layout within a panel. I have added a menu option button that when pressed, loads another layout in the panel. All is working fine except !

If i press the back button when the option layout is active, the application just terminates, rather than return to the previous layout that was shown.

Please could someone shed some light for me please :sign0104:

Neil
 

kickaha

Well-Known Member
Licensed User
Longtime User
You need top handle the back button yourself, there is a thread with code here

What you need to do is someting like:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
   
   If KeyCode = 4 Then ' you have pressed the back button
      If OptionShowing Then ' Just an example flag to use
         Close Options ' again just an example code
         Return True ' Consume the event so that the app does not close
      Else
         Return False ' Do not consume so the app will close or go to the previous activity
      End If   
   End If
End Sub
 
Upvote 0

dealsmonkey

Active Member
Licensed User
Longtime User
Thanks for the code kickaha.

I have decided to use multiple activities, this way the back button is reloading the layouts as I need.

Not sure if it is the preferred way to code, but it seem better for me !

neil
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Multiple activities is my preferred method, as I can keep the coding seperate and much easier to maintain.
 
Upvote 0
Top