Setting Intent.FLAG_ACTIVITY_CLEAR_TASK
will clear the target task.
You say that you need to clear the current task. You can do this by using an intermediate Activity
. Just create a simple Activity
that does the following in onCreate()
:
Intent = new Intent(this, ActivityD.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
This simple Activity should have the same taskAffinity
as ActivityA, B and C
.
When ActivityC
wants to start ActivityD
, it should start this activity instead like this:
Intent = new Intent(this, SimpleActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
This will clear the current task and then SimpleActivity
will launch ActivityD
and finish, which will finish the task.