You have so many ways to achieve your usecase
Possible way1: you can use startActivityForResult method to start the activity from C, D and based on result E you can manage to finish the activities C,D on
onActivityResult()
Possible way 2: If you don't want to keep the Activities on the backstack,
You can finish that activities C, D after they started another
Possible way 3: You can use Intent Flags to manipulate backstack
Let me know if you need further help
For your info
You can use finishAffinity() task in Activity to finish all your previous activities.
it will Finish the activity as well as all activities immediately below it
in the current task that have the same affinity. This is typically
used when an application can be launched on to another task (such as
from an ACTION_VIEW of a content type it understands) and the user
has used the up navigation to switch out of the current task and in
to its own task. In this case, if the user has navigated down into
any other activities of the second application, all of those should
be removed from the original task as part of the task switch.
Note that this finish does not allow you to deliver results
to the previous activity, and an exception will be thrown if you are trying
to do so