Switching tasks in one application
<p>I wanted to reproduce situation shown here:
<a href="http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html#TaskLaunchModes" rel="nofollow">http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html#TaskLaunchModes</a>
Where I start app using activity X0, then start activity A1 as new
task and open activity A2 as single task. Next I open activity B1 as
new task, then I start activity B2 and then I'd like to switch to
activity A2. On back I would go to A1, then B2, B1 and finally to X0.</p>

<p>Here is my manifest:</p>

<pre><code>     &lt;application
           android:icon="@drawable/icon"
           android:label="@string/app_name"&gt;
           &lt;activity
                   android:name="X0"
                   android:label="@string/app_name"&gt;
                   &lt;intent-filter&gt;
                           &lt;action
                                   android:name="android.intent.action.MAIN" /&gt;
                           &lt;category
                                   android:name="android.intent.category.LAUNCHER" /&gt;
                   &lt;/intent-filter&gt;
           &lt;/activity&gt;
           &lt;activity
                   android:name="A1"
                   android:allowTaskReparenting="false"
                   android:taskAffinity="@string/task_A"
                   android:label="@string/app_name"&gt;
           &lt;/activity&gt;
           &lt;activity
                   android:name="A2"
                   android:allowTaskReparenting="false"
                   android:taskAffinity="@string/task_A"
                   android:launchMode="singleTop"
                   android:label="@string/app_name"&gt;
           &lt;/activity&gt;
           &lt;activity
                   android:name="B1"
                   android:allowTaskReparenting="false"
                   android:taskAffinity="@string/task_B"
                   android:label="@string/app_name"&gt;
           &lt;/activity&gt;
           &lt;activity
                   android:name="B2"
                   android:allowTaskReparenting="false"
                   android:taskAffinity="@string/task_B"
                   android:launchMode="singleTask"
                   android:label="@string/app_name"&gt;
           &lt;/activity&gt;
   &lt;/application&gt;
</code></pre>

<p>At first I hadn't any allowTaskReparenting nor taskAffinity, I started
to experiment with those settings.</p>

<p>And here is my code for activity, it's the same among activities:</p>

<pre><code>   ((TextView) findViewById(R.id.title)).setText("X0" + getTaskId() + isTaskRoot()); //some debugging

   findViewById(R.id.a1).setOnClickListener(new OnClickListener() {

                   @Override
                   public void onClick(View v) {
                           Intent intent = new Intent();
                           intent.setClass(getApplicationContext(), A1.class);
                           intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                           intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                           startActivity(intent);
                   }
           });
           findViewById(R.id.a2).setOnClickListener(new OnClickListener() {

                   @Override
                   public void onClick(View v) {
                           Intent intent = new Intent();
                           intent.setClass(getApplicationContext(), A2.class);
                           startActivity(intent);
                   }
           });
           findViewById(R.id.b1).setOnClickListener(new OnClickListener() {

                   @Override
                   public void onClick(View v) {
                           Intent intent = new Intent();
                           intent.setClass(getApplicationContext(), B1.class);
                           intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                           intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                           startActivity(intent);
                   }
           });
           findViewById(R.id.b2).setOnClickListener(new OnClickListener() {

                   @Override
                   public void onClick(View v) {
                           Intent intent = new Intent();
                           intent.setClass(getApplicationContext(), B2.class);
                           startActivity(intent);
                   }
           });
</code></pre>

<p>Now I'm clicking A1, A2, B1, B2, A2 and the A2 should be from task A,
but it opens new activity A2 in stack B.</p>

<p>Is it possible to switch between tasks that I've created?</p>
