Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bring an activity to foreground (top of stack)?

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?

like image 491
user256239 Avatar asked Feb 09 '10 20:02

user256239


People also ask

How does activity come to the foreground?

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.

How do you bring a task to the front?

i. addFlags(Intent. FLAG_ACTIVITY_REORDER_TO_FRONT) ; which brings back the activity to front.

When an activity is at the top of the stack it is the?

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.

What is activity stack and how does it function?

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.


1 Answers

You can try this FLAG_ACTIVITY_REORDER_TO_FRONT (the document describes exactly what you want to)

like image 102
2 revs, 2 users 67% Avatar answered Sep 22 '22 06:09

2 revs, 2 users 67%