4

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.

ChangUZ
  • 5,380
  • 10
  • 46
  • 64

4 Answers4

6

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.

Zerga
  • 305
  • 1
  • 8
0

Clear Backstack of android, from where you are calling tabActivity

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
MohsinSyd
  • 175
  • 2
  • 13
0

Use

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

This will finish the previous activities

user2041902
  • 593
  • 1
  • 6
  • 21
0

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.

Nargis
  • 4,687
  • 1
  • 28
  • 45