Android Question kill the last activity

yaniv hanya

Active Member
Licensed User
Is there any way to cause the activity to be destroyed after calling startActivity. So that the next time i start it it will start from Activity_Create not form the Activity_Resume
 

MarcoRome

Expert
Licensed User
Longtime User
In this example you have 3 activity, Main, act_due, act_tre
The main call act_due, if you click button open act_tre, if you click on button ( in act_tre ) reopen act_due and so...
Look this code. If you have this code in act_due:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("lay_due")
    If FirstTime Then
        Log("First Time DUE")
    Else
        Log("Run Again Activity_create DUE")
    End If
    
End Sub


Sub Button1_Click
    StartActivity(act_tre)
End Sub

When you click on button act_tre reopen act_due the Activity_create it ISNT executed, but it will go directly to Resume
if you write this code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("lay_due")
    If FirstTime Then
        Log("First Time DUE")
    Else
        Log("Run Again Activity_create DUE")
    End If
    
End Sub


Sub Button1_Click
    StartActivity(act_tre)
    Activity.Finish ' <--------------- LOOK THIS
End Sub

When you click on button act_tre reopen act_due the Activity_create you see message in Log windows "Run Again Activity_create DUE" because in this cases Activity_create is executed with FirstTime = False
Anyway i don't see any reason, since you can manage everything in Pause / Resume
 

Attachments

  • Activity_first.zip
    14.5 KB · Views: 160
Upvote 0
Top