Fix new task starting in samples

Added correct intent action and category. Added separate case to
show the behavior with and without FLAG_ACTIVITY_MULTIPLE_TASK.

Bug: 28848683
Change-Id: I4ba3908b7331e6d4c5f2d78c0a861e00487fcae4
diff --git a/samples/MultiWindow/res/layout/launching_adjacent_layout.xml b/samples/MultiWindow/res/layout/launching_adjacent_layout.xml
index 3fa6c1c..52b5c89 100644
--- a/samples/MultiWindow/res/layout/launching_adjacent_layout.xml
+++ b/samples/MultiWindow/res/layout/launching_adjacent_layout.xml
@@ -30,10 +30,15 @@
             android:layout_height="wrap_content"
             android:text="@string/launch_settings_adjacent" />
         <Button
-            android:id="@+id/launch_new_task"
+            android:id="@+id/launch_new_task_single"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:text="@string/launch_new_task" />
+            android:text="@string/launch_new_task_single" />
+        <Button
+            android:id="@+id/launch_new_task_multiple"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/launch_new_task_multiple" />
         <Button
             android:id="@+id/launch_new_task_adjacent"
             android:layout_width="wrap_content"
diff --git a/samples/MultiWindow/res/values/strings.xml b/samples/MultiWindow/res/values/strings.xml
index 6c36798..20830a7 100644
--- a/samples/MultiWindow/res/values/strings.xml
+++ b/samples/MultiWindow/res/values/strings.xml
@@ -17,7 +17,8 @@
 <resources>
 
     <string name="launch_settings_adjacent">Launch settings adjacent</string>
-    <string name="launch_new_task">Launch new task</string>
+    <string name="launch_new_task_single">Launch new task, single allowed</string>
+    <string name="launch_new_task_multiple">Launch new task, multiple allowed</string>
     <string name="launch_new_task_adjacent">Launch new task adjacent</string>
     <string name="instance_number">Instance number:</string>
 </resources>
diff --git a/samples/MultiWindow/src/com/example/android/multiwindow/LaunchingAdjacentActivity.java b/samples/MultiWindow/src/com/example/android/multiwindow/LaunchingAdjacentActivity.java
index 1216ff1..4fc09cc 100644
--- a/samples/MultiWindow/src/com/example/android/multiwindow/LaunchingAdjacentActivity.java
+++ b/samples/MultiWindow/src/com/example/android/multiwindow/LaunchingAdjacentActivity.java
@@ -34,7 +34,8 @@
         super.onCreate(savedInstanceState);
         setContentView(R.layout.launching_adjacent_layout);
         findViewById(R.id.launch_settings_adjacent).setOnClickListener(this);
-        findViewById(R.id.launch_new_task).setOnClickListener(this);
+        findViewById(R.id.launch_new_task_single).setOnClickListener(this);
+        findViewById(R.id.launch_new_task_multiple).setOnClickListener(this);
         findViewById(R.id.launch_new_task_adjacent).setOnClickListener(this);
         if (savedInstanceState != null) {
             mInstanceNumber = savedInstanceState.getInt(INSTANCE_NUMBER_KEY);
@@ -47,22 +48,43 @@
 
     @Override
     public void onClick(View v) {
-        if (v.getId() == R.id.launch_settings_adjacent) {
-            Intent intent = new Intent("android.settings.SETTINGS");
-            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
-            startActivity(intent);
-        } else if (v.getId() == R.id.launch_new_task) {
-            Intent intent = new Intent(this, LaunchingAdjacentActivity.class);
-            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            startActivity(intent);
-        } else if (v.getId() == R.id.launch_new_task_adjacent) {
-            Intent intent = new Intent(this, LaunchingAdjacentActivity.class);
-            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
-                    | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
-            startActivity(intent);
+        switch (v.getId()) {
+            case R.id.launch_settings_adjacent: {
+                Intent intent = new Intent("android.settings.SETTINGS");
+                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                        | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
+                startActivity(intent);
+            }
+            break;
+            case R.id.launch_new_task_single: {
+                Intent intent = newAdjacentActivityIntent();
+                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                startActivity(intent);
+            }
+            break;
+            case R.id.launch_new_task_multiple: {
+                Intent intent = newAdjacentActivityIntent();
+                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
+                startActivity(intent);
+            }
+            break;
+            case R.id.launch_new_task_adjacent: {
+                Intent intent = newAdjacentActivityIntent();
+                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
+                        | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
+                startActivity(intent);
+            }
+            break;
         }
     }
 
+    private Intent newAdjacentActivityIntent() {
+        Intent intent = new Intent(this, LaunchingAdjacentActivity.class);
+        intent.setAction(Intent.ACTION_MAIN);
+        intent.addCategory(Intent.CATEGORY_LAUNCHER);
+        return intent;
+    }
+
     @Override
     public void onSaveInstanceState(Bundle savedInstanceState) {
         savedInstanceState.putInt(INSTANCE_NUMBER_KEY, mInstanceNumber);