Fix new task starting in samples

am: e5d940bda0

* commit 'e5d940bda03932c9218281c66c606dc94734b9be':
  Fix new task starting in samples

Change-Id: I0fa121818fed34895de7a4c97a6ced5e095c961d
This commit is contained in:
Andrii Kulian
2016-06-03 02:06:23 +00:00
committed by android-build-merger
3 changed files with 45 additions and 17 deletions

View File

@@ -30,10 +30,15 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/launch_settings_adjacent" /> android:text="@string/launch_settings_adjacent" />
<Button <Button
android:id="@+id/launch_new_task" android:id="@+id/launch_new_task_single"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="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 <Button
android:id="@+id/launch_new_task_adjacent" android:id="@+id/launch_new_task_adjacent"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -17,7 +17,8 @@
<resources> <resources>
<string name="launch_settings_adjacent">Launch settings adjacent</string> <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="launch_new_task_adjacent">Launch new task adjacent</string>
<string name="instance_number">Instance number:</string> <string name="instance_number">Instance number:</string>
</resources> </resources>

View File

@@ -34,7 +34,8 @@ public class LaunchingAdjacentActivity extends Activity implements View.OnClickL
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.launching_adjacent_layout); setContentView(R.layout.launching_adjacent_layout);
findViewById(R.id.launch_settings_adjacent).setOnClickListener(this); 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); findViewById(R.id.launch_new_task_adjacent).setOnClickListener(this);
if (savedInstanceState != null) { if (savedInstanceState != null) {
mInstanceNumber = savedInstanceState.getInt(INSTANCE_NUMBER_KEY); mInstanceNumber = savedInstanceState.getInt(INSTANCE_NUMBER_KEY);
@@ -47,22 +48,43 @@ public class LaunchingAdjacentActivity extends Activity implements View.OnClickL
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (v.getId() == R.id.launch_settings_adjacent) { switch (v.getId()) {
Intent intent = new Intent("android.settings.SETTINGS"); case R.id.launch_settings_adjacent: {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT); Intent intent = new Intent("android.settings.SETTINGS");
startActivity(intent); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
} else if (v.getId() == R.id.launch_new_task) { | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
Intent intent = new Intent(this, LaunchingAdjacentActivity.class); startActivity(intent);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); }
startActivity(intent); break;
} else if (v.getId() == R.id.launch_new_task_adjacent) { case R.id.launch_new_task_single: {
Intent intent = new Intent(this, LaunchingAdjacentActivity.class); Intent intent = newAdjacentActivityIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
| Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT); startActivity(intent);
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 @Override
public void onSaveInstanceState(Bundle savedInstanceState) { public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putInt(INSTANCE_NUMBER_KEY, mInstanceNumber); savedInstanceState.putInt(INSTANCE_NUMBER_KEY, mInstanceNumber);