Android Question [SOLVED] Clear Activity Stack

Emme Developer

Well-Known Member
Licensed User
Longtime User
Hi everybody! Is possible to clear activity stack?
I've an application in which for some reason i can't call Activity finish in one activity, so when i press one button in 2nd activity i want to close also previous acitivity.
I have 2 option, call Activity.finish in previous act by using a simple CallSubDelayed, or using this code
https://stackoverflow.com/questions/7075349/android-clear-activity-stack

I tried to do 2nd option in this way, but doesn't work.. anyone can help me? Thanks

B4X:
Dim inte As Intent
        inte.Initialize(Me,"")
        Dim ob As JavaObject = inte
        inte.Flags = Bit.Xor(ob.GetField("FLAG_ACTIVITY_NEW_TASK"),ob.GetField("FLAG_ACTIVITY_CLEAR_TASK"))
        Activity.Finish      
        StartActivity(inte)

'Also tried
        Dim inte As Intent
        inte.Initialize(Me,"")
        Dim ob As JavaObject = inte
        ob.RunMethod("addFlags",Array(ob.GetField("FLAG_ACTIVITY_NEW_TASK")))
        ob.RunMethod("addFlags",Array(ob.GetField("FLAG_ACTIVITY_CLEAR_TASK")))
        Activity.Finish      
        StartActivity(ob)

'.... and ....

Dim inte As Intent
        inte.Initialize(main,"")
        Dim ob As JavaObject = inte
        ob.RunMethod("addFlags",Array(ob.GetField("FLAG_ACTIVITY_NEW_TASK")))
        ob.RunMethod("addFlags",Array(ob.GetField("FLAG_ACTIVITY_CLEAR_TASK")))
        Activity.Finish      
        StartActivity(inte)

Thanks!
 

DonManfred

Expert
Licensed User
Longtime User
Call this in a activity 1 to go to 2nd activity and do not want to come back...
B4X:
 Activity.Finish     
StartActivity(secondactivity)
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
Call this in a activity 1 to go to 2nd activity and do not want to come back...
B4X:
 Activity.Finish    
StartActivity(secondactivity)
Hi DonManfred, thanks for your answer.
As i said, i can't call Activity.finish in 1st actitiy.
I have 3 activity, Main, A and B.

From Main i will go to A. From A i will go to B (in a i can't call Activity finish). In B i want to go to Main and clear also A
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
Main activity is the first page in Application. A activity is a setting page. From Setting page i will go in a second Activity, B, that is language page. From B i want to change app language, so i reset some variables, close B activity, and return in Main.
I want that when an user click on back in setting page, will return in Main page. If i close activity before starting Language page, when user clicks on Back button in Language page will return on main page. But if i don't close Setting page, after that user goes in Main page, if clicks on back button then returns on Settings (with previous language setted). A solution is to set language in Activity_Resume in setting, but i thinks is easier clear activities stack.

Sorry for my english, i hope i clearly explain
 
Upvote 0

Similar Threads

  • Locked
  • Question
Android Question Activity.Finish
Replies
17
Views
3K
Replies
5
Views
1K
Replies
3
Views
2K
Replies
28
Views
4K
Top