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??
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With