Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a particular activity as a root activity in stack

i have a set of activities on my stack Say A-->B-->C. when i launch the activity named 'D' it should get fired as the root activity of my application and all the other activities(A,B,C) should get cleared from my stack once Activity D is launched.Can any one tell me as how to do this

like image 476
Lysogen Avatar asked Feb 10 '11 14:02

Lysogen


People also ask

What is root activity?

In android when you launch an app Main or root activity is first activity to be executed. For root activity it is compulsory to have android. intent. action. MAIN and android.

What method can an activity use to start another activity?

To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.

What is an activity stack?

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.

How can I run a particular activity in Android Studio?

Choose Edit Configuration from the list. Now from the Launch Option Select the Specified Activity and start typing in the activity text input, the android studio will automatically show you the list of all activities, select one from them or write the name of your activity.


1 Answers

Set root activity

    Intent intent = new Intent(this, DActivity.class);

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    startActivity(intent);
like image 194
Afzaal Ahmad Avatar answered Oct 21 '22 10:10

Afzaal Ahmad