ChangUZ
ChangUZ

Reputation: 5440

How to Clear all previous activities~?

Activity Flow in my app.

WelcomeActivity -> SignInActivity -> SignUpActivity -> TabsActivity(this is main) -> ...


Activity Stack


I want to close all previous activities (Welcome, SignIn, SignUp) when start TabsActivity.

I try several method...

  1. TabsActivity. clear task on launch=true ? but not work (maybe)

  2. TabsActivity. launch mode = singleTask ? but not work

But I do not want to "save 3 activities and call each activity.finish()"

Depending on the situation, "available 2 or 4 activities not 3", or "I do not know What activities is in activity stack".


I want to clear all previous activities, regadless of any situation.

Help me :)

Sorry my poor english... Thanks.

Upvotes: 4

Views: 7574

Answers (4)

MohsinSyd
MohsinSyd

Reputation: 175

Clear Backstack of android, from where you are calling tabActivity

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Upvotes: 0

Zerga
Zerga

Reputation: 305

If I understand correctly, you might want to try starting your TabsActivity with the following code:

    Intent intent = new Intent(getApplicationContext(), TabsActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

The flag Intent.FLAG_ACTIVITY_CLEAR_TOP clears the history.

Upvotes: 6

Nargis
Nargis

Reputation: 4787

To Close Previous Activities ,you should start New Activity with startActivityForResult and then before finishing the current Activity with finish() call , setResult(value) for previous Activity ,the previous Activity will then get a callback where you can call finish() for the previous Activity.

Upvotes: 0

user2041902
user2041902

Reputation: 593

Use

Intent intent = new Intent(getApplicationContext(), ClassToLaunch.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

This will finish the previous activities

Upvotes: 0

Related Questions