Android Question Back button select case statement

anaylor01

Well-Known Member
Licensed User
Longtime User
I want to create a select case statement for the back button. I guess my main problem is how to dectect which layout is loaded. So something like this.

Select case Backbutton
case Layout("Main") loaded
Activity.removelayout("Main")
Acitivty.Loadlayout("test")
case layout("Two")loaded
Activity.removelayout("Two")
Acitivty.Loadlayout("THree")
 

mangojack

Expert
Licensed User
Longtime User
This works as expected ..
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
   If KeyCode = KeyCodes.KEYCODE_BACK Then
      Select layout
         Case  "NewGame" ,"Options", "LoadGame"
            allinvisible
            MainMenu                     
            Return True                                
         Case "HowtoPlay"
            allinvisible
            Options                     
            Return True                 
         Case  "GamePlay"      
            Dim result As Int
            result =    Msgbox2("Exit Game?", "Exit", "Exit", "Main Menu", "Continue playing",Null)
            If result = DialogResponse.POSITIVE Then
               Msgbox(gmid,"gameid")             
               ExitApplication                       
            Else IF result = DialogResponse.CANCEL Then
               allinvisible
               MainMenu                     
               Return True                             
            Else If result = DialogResponse.NEGATIVE Then
               'continue playing             
               Return True
            End If         
         Case "MainMenu"
            ExitApplication                 
      End Select
   End If
End Sub

Unless I have missed something lately .. I don't believe you can trap the Home Key button press.

I think it would have been good idea if you followed @Erel's suggestion in post#2 to have separate activities for your game,
versus loading multiple layouts in a single activity. It would have made it easier to handle the above scenario.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…