1
Activity A -> Activity B -> Activity C -> Activity D 

Let's assume we have this flow. From Activity D I want to come back to Activity B, so my stack should look after I close Activity D like this:

Activity A -> Activity B 

I have used startActivity(this, Activity B).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) but it does not restore the activity from back stack, it created it again;

When I initially start Activity B from Activity A I had sent some data in bundle which is lost now; So, do I have to sent that data through Activity C -> Activity D so I can have it and send it back to Activity B when I open it form Activity D, or I can some how restore Activity B?

ghita
  • 2,746
  • 7
  • 30
  • 54
  • you can start activity D with startActivityForResult. for those cases you want to close activity C also when D is closed, pass some value to the onActivityResult of activity C and handle it from there. – Viswas Kg Apr 30 '19 at 11:22

1 Answers1

1

Using android:taskAffinity could be an option for you.

You can configure ActivityC and ActivityD with the same affinity. When ActivityD is closed using Activity#finishAffinity() ActivityD and ActivityC are finished -- ActivityB is resumed with its previous intent.

hartwecm
  • 219
  • 1
  • 4