Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity with Flag FLAG_ACTIVITY_CLEAR_TOP (android)

Tags:

android

I have stack of activities launched after one another.
but in one of the activity I need to launch that particular activity with flag FLAG_ACTIVITY_CLEAR_TOP.

So that it will finish all the previous activities and start.

Problem I am facing that i don't want to finish one of the activity from the stack it should be presence on back of the newly launched activity.

Suppose I have activities [A] [B] [C] [D]
I am starting [D] activity with flag FLAG_ACTIVITY_CLEAR_TOP after starting activity [D] it will destroy all the activities, I want activity [B] to be kept running on the back and when we press back key on [D] it should display activity [B].

How to do this?

Thanks,
PP.

like image 784
User7723337 Avatar asked Mar 03 '11 09:03

User7723337


People also ask

What is flag activity clear top?

Flag Activity Clear Top destroys target activity and than creating it. Android, what Intent flags are recommended for Activities started by Notifications.

What are flags in Android?

A flag is a setting that allows the configuration of or gating of some logic or feature. It can almost be thought of as a simple constant but with some extra functionality that we will go over in this document.

How do you add multiple flags to intent?

Use addFlags() so that you can add multiple number of Flags to Intent.

What is FLAG_ACTIVITY_NEW_TASK?

The flags you can use to modify the default behavior are: FLAG_ACTIVITY_NEW_TASK. Start the activity in a new task. If a task is already running for the activity you are now starting, that task is brought to the foreground with its last state restored and the activity receives the new intent in onNewIntent() .


1 Answers

One solution is to call Activity [B] with flag FLAG_ACTIVITY_CLEAR_TOP, this will destroy all activities but [B]. After that, call Activity [D].

like image 89
Mudassir Avatar answered Nov 01 '22 03:11

Mudassir