import android.app.Activity;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
*/
//BEGIN_INCLUDE(intent_array)
private Intent[] buildIntentsToViewsLists() {
- // We will use FLAG_ACTIVITY_CLEAR_TASK to complete replace our
- // current task with a new Intent.
+ // We are going to rebuild our task with a new back stack. This will
+ // be done by launching an array of Intents, representing the new
+ // back stack to be created, with the first entry holding the root
+ // and requesting to reset the back stack.
Intent[] intents = new Intent[3];
- // The main activity started from launcher is action MAIN and
- // category LAUNCHER; we want to match that.
- Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.addCategory(Intent.CATEGORY_LAUNCHER);
- // We will use FLAG_ACTIVITY_CLEAR_TASK to completely replace our
- // current task with a new Intent.
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_CLEAR_TASK);
-
- // Set the actual activity to launch.
- intent.setClass(IntentActivityFlags.this, com.example.android.apis.ApiDemos.class);
- intents[0] = intent;
+ // First: root activity of ApiDemos.
+ // This is a convenient way to make the proper Intent to launch and
+ // reset an application's task.
+ intents[0] = Intent.makeRestartActivityTask(new ComponentName(this,
+ com.example.android.apis.ApiDemos.class));
- intent = new Intent(Intent.ACTION_MAIN);
+ Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(IntentActivityFlags.this, com.example.android.apis.ApiDemos.class);
intent.putExtra("com.example.android.apis.Path", "Views");
intents[1] = intent;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
+import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
Intent[] intents = new Intent[4];
// First: root activity of ApiDemos.
- // The main activity started from launcher is action MAIN and
- // category LAUNCHER; we want to match that.
- intents[0] = new Intent(Intent.ACTION_MAIN);
- intents[0].addCategory(Intent.CATEGORY_LAUNCHER);
- // We will use FLAG_ACTIVITY_CLEAR_TASK to completely replace our
- // current task with a new Intent.
- intents[0].addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- intents[0].setClass(this, com.example.android.apis.ApiDemos.class);
+ // This is a convenient way to make the proper Intent to launch and
+ // reset an application's task.
+ intents[0] = Intent.makeRestartActivityTask(new ComponentName(this,
+ com.example.android.apis.ApiDemos.class));
// "App"
intents[1] = new Intent(this, com.example.android.apis.ApiDemos.class);