In Android, I defined an activity ExampleActivity.
When my application was launched, an instance of this A-Activity was created, say it is A
. When user clicked a button in A
, another instance of B-Activity, B was created. Now the task stack is B-A, with B at the top. Then, user clicked a button on B, another instance of C-Activity, and C was created. Now the task stack is C-B-A, with C at the top.
Now, when user click a button on C, I want the application to bring A to the foreground, i.e. make A to be at the top of task stack, A-C-B.
How can I write the code to make it happen?
Activity or dialog appears in foregroundWhen the covered activity returns to the foreground and regains focus, it calls onResume() . If a new activity or dialog appears in the foreground, taking focus and completely covering the activity in progress, the covered activity loses focus and enters the Stopped state.
i. addFlags(Intent. FLAG_ACTIVITY_REORDER_TO_FRONT) ; which brings back the activity to front.
If no task for the app exists (because it hasn't been used recently), a new task is created, and the app's “main” activity is opened as the stack's root activity. When the current activity switches to a new one, the new activity is pushed to the top of the stack and takes control of the attention.
A task is a collection of activities that users interact with when trying to do something in your app. These activities are arranged in a stack—the back stack—in the order in which each activity is opened. For example, an email app might have one activity to show a list of new messages.
You can try this FLAG_ACTIVITY_REORDER_TO_FRONT
(the document describes exactly what you want to)
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