D T
D T

Reputation: 3746

Why can't close all activities?

I have 3 activities: A. B ,...., C From A: Click open B. From B: click open C

At C: i want close all activities (B,..,C) and back to A: I use this code, but it only close activity C, not close activities (B,...) :

  Intent intent = new Intent(getApplicationContext(), A.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Bundle b = new Bundle();
    b.putBoolean("UpdateVersion", true);
    intent.putExtras(b);
    startActivity(intent);

Why can't close all activities?

Upvotes: 0

Views: 107

Answers (2)

EpicPandaForce
EpicPandaForce

Reputation: 81529

You need to look into calling startActivityForResult() so that on the callback of the created Activity of C, the previous Activity of B gets finished as well. The callback function is called onActivityResult(), and in that, you want to call finish().

Example:

ActivityB:

Intent i = new Intent(this, ActivityC.class);
startActivityForResult(i, 0);

...

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    this.finish();
}

ActivityC:

//do stuff

This way, when you press Back (or call finish()) in ActivityC, it will call back on ActivityB's onActivityResult() function, and it will end them both.

Upvotes: 1

Hariharan
Hariharan

Reputation: 24853

Try this..

After starts from B Activity use finish()

startActivity(intent);
finish();

Upvotes: 2

Related Questions