title: Android: Task affinity & Clear task
body: <p>I am having three modules - ModuleA, ModuleB, ModuleC</p>
  
  <pre><code>ModuleA - 1 activity
  </code></pre>
  
  <p>MainActivity - no task affinity</p>
  
  <pre><code>Module B - 3 activities 
  </code></pre>
  
  <p>Activity_A
  task affinity = "com.performance.poc.main"</p>
  
  <p>Activity_B
  task affinity = "com.performance.poc.main"</p>
  
  <p>Activity_C 
  task affinity = "com.performance.poc.main"</p>
  
  <pre><code>Module C - 1 activity 
  </code></pre>
  
  <p>Activity_D - no task affinity</p>
  
  <pre><code>Navigation Case 1:
  </code></pre>
  
  <ol>
  <li>MainActivity</li>
  <li>on btn Click - start Activity_A Intent.FLAG_ACTIVITY_NEW_TASK</li>
  <li>on btn Click - start Activity_B</li>
  <li>on btn Click - start Activity_C </li>
  <li><p>on btn Click - start Activity_D Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK</p>
  
  <p><em><strong>Expected Task Result:</strong>    <br>
  <strong>Task com.performance.poc</em></strong><br>
   Activity_D <br>
   MainActivity<br></p>
  
  <p><em><strong>Task com.performance.poc.main</em></strong> <br>
  Activity_C<br>
  Activity_B<br>
  Activity_A<br></p>
  
  <p>Expected : on starting the Activity_D task com.performance.poc.main should be cleared. 
  Actual : Still Activity_A, Activity_B, Activity_C remains but MainActivity is cleared.</p></li>
  </ol>
  
  <hr>
  
  <pre><code>Navigation Case 2:
  </code></pre>
  
  <ol>
  <li>MainActivity</li>
  <li>on btn Click - start Activity_A Intent.FLAG_ACTIVITY_NEW_TASK</li>
  <li>on btn Click - start Activity_B </li>
  <li>on btn Click - start Activity_C Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK</li>
  <li>on btn Click - start Activity_D Intent.FLAG_ACTIVITY_NEW_TASK</li>
  </ol>
  
  <p><em><strong>Expected Task Result:</em></strong>    <br></p>
  
  <p><em><strong>Task com.performance.poc</em></strong>    <br>
  Activity_D    <br>
  MainActivity    <br></p>
  
  <p><em><strong>Task com.performance.poc.main</em></strong>    <br></p>
  
  <p>Activity_C    <br>
  Activity_B    <br>
  Activity_A    <br></p>
  
  <pre><code> Expected : on starting the Activity_C, in task com.performance.poc.main, Activity_A, Activity_B should be cleared. 
  Actual :  Activity_A, Activity_B is cleared as expected.
  </code></pre>
  
  <p>My Question here is why in Case1, even though Activity_A, Activity_B, Activity_C are in same task and it is not clearing these and clearing MainActivity.</p>
  
  <p>The Clear_Task should clear the existing task of the activity <strong>from which startActivity is called with intent new_task and clear_task.</strong>  or it will clear the task of target activity.</p>
  
  <pre><code>If it is Target activity, I need to clear the task of the leaving activity, is there any way to do it?
  </code></pre>