0

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.

Gizmomogwai
  • 2,496
  • 1
  • 20
  • 21
  • Already answered here: https://stackoverflow.com/questions/3408388/how-to-kill-sub-activities-and-bring-activity-to-top-of-stack – Gizmomogwai Sep 20 '19 at 14:12

2 Answers2

1

In Activity D:

Intent intent = new Intent(ActivityD.this, ActivityA.class);
                intent.putExtra("param", param); //optional
                startActivity(intent);
                finish();
Baby
  • 326
  • 4
  • 16
  • After reach startActivity(intent), it will make new stack of activity right? I mean if activity A -> B -> D, in activity D startActivity (intent), it will be A -> B -> D -> A, and it will reach finish line if latest A is finished and will be like this activity A -> B in memory. What I want is if in activity D finish I want to reach to activity A, example activity A -> B -> D, it activity D is done, what I want is activity A -> B -> D destroyed and activity A is re-created or resume on activity A – Kazuto Rito Sep 20 '19 at 13:21
  • ok. you add "finish()" after "startActivity()" in your activities and A, B and D activities will be destroyed – Baby Sep 20 '19 at 14:13
0

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.

Rahul Kushwaha
  • 5,473
  • 3
  • 26
  • 30
  • After reach startActivity(intent), it will make new stack of activity right? I mean if activity A -> B -> D, in activity D startActivity (intent), it will be A -> B -> D -> A, and it will reach finish line if latest A is finished and will be like this activity A -> B in memory. What I want is if in activity D finish I want to reach to activity A, example activity A -> B -> D, it activity D is done, what I want is activity A -> B -> D destroyed and activity A is re-created or resume on activity A – Kazuto Rito Sep 20 '19 at 13:21
  • Then do like this when you call A -> B -> D make sure to implement finish() method every time transition from one activity to another. – Rahul Kushwaha Sep 20 '19 at 13:31
  • @KazutoRito when activity is called from one activity to another onPause – Rahul Kushwaha Sep 20 '19 at 13:31