Android Question Button exit application

Alberto SN

Member
Licensed User
Hi,

I need for my app one button for exit application with a question message.

This is the code:

B4X:
Sub lblExit_Click
    Dim Answ As Int
    Dim Txt As String = "Are you sure?"
    Dim msgSi As String = "yes"
    Dim msgNo As String = "no"

    Answ=Msgbox2(Txt,"Question",msgSi,"",msgNo,LoadBitmap(File.DirAssets, "logo.png"))
    If Answ=DialogResponse.POSITIVE Then
        Activity.finish
    End If

When I tap button, application go to activity back, but don't close the app.

Please, help me.

Thanks :)
 

JordiCP

Expert
Licensed User
Longtime User
With Activity.Finish you are telling the current activity to terminate. But if this Activity has been started from the Main Activity (or any other), this will be called again in Activity_Resume (or perhaps Activity_Create)

If this is the case, you can:

In your second activity, modify your lblExit_click
B4X:
If Answ=DialogResponse.POSITIVE Then
  Main.want2exit=True
  Activity.finish
EndIf

Also, modifiy your main module. Add the control variable in Process_Globals and check it in Activity_Resume
B4X:
Sub Process_Globals
  Dim want2exit as Boolean = False
End Sub

Sub Activity_Resume
  if want2exit=True then
    Activity.Finish
  else
    ....
  end if
End Sub
 
Upvote 0

GudEvil

Member
Licensed User
Longtime User
is msgbox2 is in main activity or in sub activity??

you program control might be in sub activity n you are closing sub_activity. You got to close main activity to once it resumes.
You can handle main_activity_resume_sub with flag that it should terminate or not..

-m
 
Upvote 0

Alberto SN

Member
Licensed User
is msgbox2 is in main activity or in sub activity??

you program control might be in sub activity n you are closing sub_activity. You got to close main activity to once it resumes.
You can handle main_activity_resume_sub with flag that it should terminate or not..

-m

msgbox2 is in sub activity, I tried change to True want2exit (thans JordiCP for your post) but same results.
it is possible that the activities are not closing properly?
my app got +5 sub activities and idk if it is necessary to close sub activities (I'm new b4x dev).

Thanks a lot
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I would add the same condition in all the Activity_Resume of the different activities

If this doesn't work, would use debug mode (through USB). You will see in the logs which activitites are being paused/resumed and decide if this makes sense
 
Upvote 0
Top