You can specify FLAG_ACTIVITY_CLEAR_TOP
flag in the Intent
used to launch ActivityA
.
Intent intent = new Intent(this, ActivityA.class);
intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP );
startActivity(intent);
If ActivityA
being launched is already running in the current task, then all of the other activities on top of it will be closed including ActivityA
and ActivityA
is restarted with the new Intent. There will be no need to call finish()
on ActivityB
explicitly.