FLAG_ACTIVITY_CLEAR_TOP is clearing activity from another task
<p>I am finding it hard to understand how the Android behaves with tasks and activities and need a solution on this one particular problem of mine. </p>

<p>I have a <strong>TabActivity A</strong> with <strong>singleTask</strong> as launchMode in manifest, and is the launcher as well. This internally starts two other <strong>Activities B, C</strong> upon visiblity(or clicks) of respective tabs. Now considering that activity B was started along with A, the task back stack becomes 
<strong>Task 1 [ A B ]</strong></p>

<p>I also happen to run a <strong>Service (X)</strong> in background. After sometime, on some event, Service X opens a new <strong>Activity D</strong> ( which is not part of the tab activity's specs ). Activity D is specified launchMode as <strong>singleTask</strong> and affinity different than the package. Since services can directly start the activities, I had to provide <strong>FLAG_ACTIVITY_NEW_TASK</strong>. All goes well and the activity D is created and displayed. </p>

<p>With the explainations from developer.android.com about the tasks creation and all, the new Activity D should be created in a new task of its own. Thus the whole viewpoint should look like</p>

<p>[<strong>Background</strong> Task 1 [ A B ]][<strong>Foreground</strong> Task 2 [ D ]]</p>

<p>Now there is a way provided in activity D to go to Activity A and the intent flag is set to <strong>FLAG_ACTIVITY_CLEAR_TOP</strong>. </p>

<p>With my understanding, this flag should clear all the activities above A that are in the task of which A is the root activity. Meaning it should destroy activity B only. i.e. the viewpoint should look like 
[<strong>Background</strong> Task 2 [ D ]] [<strong>Foreground</strong> Task 1 [ A ]]</p>

<p>But in my case, it is destroying activity D as well, which is definetly not the behaviour i want since i want the Acitivity D to be present all the time unless explicitly finished by user. After navigating, the stack looks like
[<strong>Foreground</strong> Task 1 [ A ]].</p>

<p>Am I doing something wrong here? If the above behavior is the expected one in Android, then is there a way where I can start A from D without clearing D but finishing all other activities between A &amp; D? </p>
