Android Question Not all code paths return a value

ronell

Well-Known Member
Licensed User
Longtime User
i have warning in my code(see title)


B4X:
Sub activity_KeyPress (KeyCode As Int) As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Private ans As Int
        ans = Msgbox2("Do you want to close the app?", "Close App","Yes","Logout","No", Null)
        If ans = DialogResponse.POSITIVE Then
            Activity.Finish
        Else If ans = DialogResponse.CANCEL  Then
            Activity.LoadLayout("frmlogin")
        Else
        
        End If
        Return True
      
    End If
End Sub

should i just ignore the warning ?
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Hi,

B4X:
Sub activity_KeyPress (KeyCode As Int) As Boolean

If KeyCode = KeyCodes.KEYCODE_BACK Then
   
        Private ans As Int
        ans = Msgbox2("Do you want to close the app?", "Close App","Yes","Logout","No", Null)
           
        If ans = DialogResponse.POSITIVE Then
            Activity.Finish
        Else If ans = DialogResponse.CANCEL  Then
            Activity.LoadLayout("frmlogin")
        Else
   
        End If
   
        Return True
           
        Else 'Add this.
       
          Return False 'Add this.
 
    End If

End Sub

I have not tested your code.
 
Last edited:
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
See this:

B4X:
Sub activity_KeyPress (KeyCode As Int) As Boolean 'Returns a value.

Adding this:
B4X:
Else
     Return False

The value will always be returned.
 
Upvote 0
Top