mas_bejo
mas_bejo

Reputation: 607

Android Clear Some Activity on Back Stack

Let Say I have A -> B -> C -> D or A -> C-> D

when D is finish I want to Back but skip C, it will back to A or B.

But When User use back button it will back normally D -> C -> B -> A or D -> C -> A

How we can do it in android?

Upvotes: 1

Views: 109

Answers (3)

sakshi Agrawal
sakshi Agrawal

Reputation: 85

You can use

android:noHistory="true"

in manifest while declaring activity for activity B

Upvotes: 1

Mayur
Mayur

Reputation: 735

Write this code in B Activity

public void gotoC()
{
  Intent intent = new Intent(B.this, C.class);
    startActivityForResult(intent, 10);
}

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case 10:


            }
        }
    }

@Override
    public void onBackPressed() {

            super.onBackPressed();

    }

ForwardActivityResult in C Class when you call Intent to go D Activity

 public void gotoD()
{
Intent intent = new Intent(Activity.C, D.class);
      intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
      startActivity(intent);
      finish();
}

In D Activity GO to B activity Call RESULT_OK

public void gotoB()
{
Intent intent = new Intent();
     setResult(RESULT_OK, intent);
     finish();
}

Upvotes: 2

Takumi Pham
Takumi Pham

Reputation: 1

I think you can use this code before open D finish()

Upvotes: -1

Related Questions