I am trying to use ExitApplication form a Code Module. There are no compile errors, the program runs just find. Here is the segment:
B4X:
Select windowLink
Case "$$Main$$_AboutScreen"
changeWindow("AboutScreen")
linkFound = True
Case "$$Main$$_Exit"
Dim question_answer As String
question_answer = showQuestion("Are you sure you want to exit?", "Exit?", "Yes", "No, bring me back")
If(question_answer = "YES") Then
ExitApplication
End If
linkFound = True
End Select
Jon, ShowQuestion() is a more advanced method which improves your dynamic performance in different scenarios. I haven't done anything special yet though. Also, ShowQuestion will remind me. I've got used to splitting the logic as much as I can. This sub allow me for example to start logging at a certain point. It would also allow me to track user's decision, etc...
The current code is:
B4X:
Sub showQuestion(Question As String, Title As String, YES As String, NO As String)
Dim result As Int
Dim icon As Bitmap : icon = Null
If(Title = "") Then
Title = "Question"
End If
If(YES = "") Then
YES = "OK"
End If
If(NO = "") Then
NO = "No, thanks"
End If
result = Msgbox2(Question, Title, YES, "", NO, Null)
Return result
End Sub
My ExitApplication question is still there though...
Ahh, I see. So you are already using MsgBox2. In that case you need to change your code a little, as MsgBox2 returns an int, not a string. This works:
B4X:
Sub showQuestion(Question As String, Title As String, YES As String, NO As String)
Dim result As Int
Dim icon As Bitmap : icon = Null
If(Title = "") Then
Title = "Question"
End If
If(YES = "") Then
YES = "OK"
End If
If(NO = "") Then
NO = "No, thanks"
End If
result = Msgbox2(Question, Title, YES, "", NO, Null)
If result = -1 Then
Return "YES"
Else
Return "NO"
End If
End Sub
Jon, I've just come here to post my code where I reached the same solution:
Thanks anyway!
B4X:
Sub showQuestion(Question As String, Title As String, YES As String, NO As String)
Dim result As Int
Dim answer As String
Dim icon As Bitmap : icon = Null
If(Title = "") Then
Title = "Question"
End If
If(YES = "") Then
YES = "OK"
End If
If(NO = "") Then
NO = "No, thanks"
End If
result = Msgbox2(Question, Title, YES, "", NO, Null)
If(result = DialogResponse.POSITIVE) Then
answer = YES
Else If(result = DialogResponse.NEGATIVE) Then
answer = NO
End If
Return answer
End Sub
It is clear now but now another question stays in my mind:
- Is it better to keep the Exit menu in my Auto-menu-generators and use ExitApplication from within the code module?
- Or, exclude the Exit from automatic-generation, add it manually within its own activity and use Activity.Finish?