How to destroy previous activity in Activity?

dev_android picture dev_android · May 7, 2012 · Viewed 12.9k times · Source

I have four activity, i.e. A, B, C and D. A launches B, B launches C, C launches D. When C is launching D, I want to destroy the activity B depending on the situation(logic for that will remain in activity C) so that when I go back From D, it will follow D->C->A path. So I want to destroy activity B from C. How it is possible?

Answer

Raghu Mudem picture Raghu Mudem · May 7, 2012

finish Activity B when you are calling Activity C depends on your logic. For example

if(true){
Intent in = new Intent(B.this,c.class);
startActivity(c);
}
else
{
Intent in = new Intent(B.this,c.class);
startActivity(c);
finish();
}