Kazuto Rito
Kazuto Rito

Reputation: 5

How to finish an activity but I don't want go to previous activity (goto another activity)

Let say there is an activity stack A -> B -> C -> D, from activity D, I want to finish it and go to activity A. It's ok to destroy activity B and C, btw. activity D can be accessed from activity A / B / C. So If I call activity D from B (A -> B -> D), I still want to go to activity A.

Upvotes: 0

Views: 60

Answers (2)

Rahul Kushwaha
Rahul Kushwaha

Reputation: 6732

Do like this:-

Call the Intent on the onBackpressd() method.It will go on that activity which you want. Like:-

 @Override
    public void onBackpressd() {
        super.onBackpressd();
       Intent intent = new Intent(ActivityD.this, ActivityA.class);
                    intent.putExtra("param", param); //optional
                    startActivity(intent);
                    finish();
    }

Hope this will help you.

Upvotes: 0

Baby
Baby

Reputation: 326

In Activity D:

Intent intent = new Intent(ActivityD.this, ActivityA.class);
                intent.putExtra("param", param); //optional
                startActivity(intent);
                finish();

Upvotes: 1

Related Questions