Android Question How to kill a particular activity

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi,

I have a dashboard activity which opens another 3 (A->B->C) activities successively in a flow.
In C, I call a job and if it succeeds i want to kill all A/B/C activities and return back to dashboard.

I have searched forum but could not find how to kill a particular activity.

Can some please give some clue.

Thanks
 

teddybear

Well-Known Member
Licensed User
Did you try doing activity.finish?
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
B4X:
'Starter
Dim kill as boolean

'Activiy C'
Sub btn_close_Click
  Starter.kill = True
  Activity.Finish
End Sub

'Activity B
Sub Activity_Resume
    If Starter.kill = True Then
        Activity.Finish
        Return
    End If
End Sub

'Activity A
Sub Activity_Resume
    If Starter.kill = True Then
        Starter.kill = False
        Activity.Finish
        Return
    End If
End Sub

If B4XPage
B4X:
B4XPage_Appear - Called whenever the page becomes visible.
B4XPage_Disappear - Called whenever a visible page disappear
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
B4X:
'Starter
Dim kill as boolean

'Activiy C'
Sub btn_close_Click
  Starter.kill = True
  Activity.Finish
End Sub

'Activity B
Sub Activity_Resume
    If Starter.kill = True Then
        Activity.Finish
        Return
    End If
End Sub

'Activity A
Sub Activity_Resume
    If Starter.kill = True Then
        Starter.kill = False
        Activity.Finish
        Return
    End If
End Sub

If B4XPage
B4X:
B4XPage_Appear - Called whenever the page becomes visible.
B4XPage_Disappear - Called whenever a visible page disappear
Many Thanks MarcoRome.
Seems like we can close all activities but not selected ones. I will go with your suggestion.
Juzer
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I have been using it, I need to close any xyx activity where it doesnt work.
Add a sub in every activity you want to close,
B4X:
sub closeMe
    activity.finish
end sub
Add a sub closeAll in a service module, such as starter
B4X:
sub closeAll
    callsubdelay(C, "closeMe")
    callsubdelay(B, "closeMe")
    callsubdelay(A, "closeMe")
end sub
You can call starter.closeAll in C activity after jobdone
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
Add a sub in every activity you want to close,
B4X:
sub closeMe
    activity.finish
end sub
Add a sub closeAll in a service module, such as starter
B4X:
sub closeAll
    callsubdelay(C, "closeMe")
    callsubdelay(B, "closeMe")
    callsubdelay(A, "closeMe")
end sub
You can call starter.closeAll in C activity after jobdone
Cool teddybear, That's lesser riskier. I had done it through starter boolean variable but it needed to be reset.
Thanks A Lot
Juzer
 
Upvote 0
Top