Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching Between Activities Without Closing Them

So basically I'm stuck.... I want to switch between activities without closing the activities... For instance, "Activity 1" has the webpage Google and "Activity 2" has Facebook... How can I switch between both actives without the webpages closing and reopening??

like image 494
Kezxi Avatar asked Oct 13 '25 05:10

Kezxi


1 Answers

to rearrange activites in the stack without opening and closing them, you can do the following (when launching an Activity):

Intent intent = new Intent(this, TargetActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

DO NOT call finish()!

This will look in the stack and see if an instance of TargetActivity already exists. If it does, it will simply be moved to the top of the stack (so that the user can see it). If no such instance exists in the stack, a new one will be created. So you don't need to know if an instance already exists or not.

like image 149
David Wasser Avatar answered Oct 16 '25 02:10

David Wasser