Skip to content

Commit 39f412d

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "API modifications for TaskStackBuilder" into jb-dev
2 parents 69387f4 + f78a844 commit 39f412d

File tree

3 files changed

+80
-15
lines changed

3 files changed

+80
-15
lines changed

api/current.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,17 +4001,20 @@ package android.app {
40014001
method public void setDefaultTab(int);
40024002
}
40034003

4004-
public class TaskStackBuilder implements java.lang.Iterable {
4004+
public class TaskStackBuilder {
40054005
method public android.app.TaskStackBuilder addNextIntent(android.content.Intent);
4006+
method public android.app.TaskStackBuilder addNextIntentWithParentStack(android.content.Intent);
40064007
method public android.app.TaskStackBuilder addParentStack(android.app.Activity);
40074008
method public android.app.TaskStackBuilder addParentStack(java.lang.Class<?>);
40084009
method public android.app.TaskStackBuilder addParentStack(android.content.ComponentName);
4009-
method public static android.app.TaskStackBuilder from(android.content.Context);
4010-
method public android.content.Intent getIntent(int);
4010+
method public static android.app.TaskStackBuilder create(android.content.Context);
4011+
method public android.content.Intent editIntentAt(int);
40114012
method public int getIntentCount();
4013+
method public android.content.Intent[] getIntents();
40124014
method public android.app.PendingIntent getPendingIntent(int, int);
4013-
method public java.util.Iterator<android.content.Intent> iterator();
4015+
method public android.app.PendingIntent getPendingIntent(int, int, android.os.Bundle);
40144016
method public void startActivities();
4017+
method public void startActivities(android.os.Bundle);
40154018
}
40164019

40174020
public class TimePickerDialog extends android.app.AlertDialog implements android.content.DialogInterface.OnClickListener android.widget.TimePicker.OnTimeChangedListener {

core/java/android/app/Activity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2710,7 +2710,7 @@ public boolean onNavigateUp() {
27102710
Intent upIntent = getParentActivityIntent();
27112711
if (upIntent != null) {
27122712
if (shouldUpRecreateTask(upIntent)) {
2713-
TaskStackBuilder b = TaskStackBuilder.from(this);
2713+
TaskStackBuilder b = TaskStackBuilder.create(this);
27142714
onCreateNavigateUpTaskStack(b);
27152715
onPrepareNavigateUpTaskStack(b);
27162716
b.startActivities();

core/java/android/app/TaskStackBuilder.java

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import android.content.pm.ActivityInfo;
2323
import android.content.pm.PackageManager;
2424
import android.content.pm.PackageManager.NameNotFoundException;
25+
import android.os.Bundle;
2526
import android.util.Log;
2627

2728
import java.util.ArrayList;
28-
import java.util.Iterator;
2929

3030
/**
3131
* Utility class for constructing synthetic back stacks for cross-task navigation
@@ -56,7 +56,7 @@
5656
* from the design guide.
5757
* </div>
5858
*/
59-
public class TaskStackBuilder implements Iterable<Intent> {
59+
public class TaskStackBuilder {
6060
private static final String TAG = "TaskStackBuilder";
6161

6262
private final ArrayList<Intent> mIntents = new ArrayList<Intent>();
@@ -73,7 +73,7 @@ private TaskStackBuilder(Context a) {
7373
* @param context The context that will launch the new task stack or generate a PendingIntent
7474
* @return A new TaskStackBuilder
7575
*/
76-
public static TaskStackBuilder from(Context context) {
76+
public static TaskStackBuilder create(Context context) {
7777
return new TaskStackBuilder(context);
7878
}
7979

@@ -89,6 +89,30 @@ public TaskStackBuilder addNextIntent(Intent nextIntent) {
8989
return this;
9090
}
9191

92+
/**
93+
* Add a new Intent with the resolved chain of parents for the target activity to
94+
* the task stack.
95+
*
96+
* <p>This is equivalent to calling {@link #addParentStack(ComponentName) addParentStack}
97+
* with the resolved ComponentName of nextIntent (if it can be resolved), followed by
98+
* {@link #addNextIntent(Intent) addNextIntent} with nextIntent.</p>
99+
*
100+
* @param nextIntent Intent for the topmost Activity in the synthesized task stack.
101+
* Its chain of parents as specified in the manifest will be added.
102+
* @return This TaskStackBuilder for method chaining.
103+
*/
104+
public TaskStackBuilder addNextIntentWithParentStack(Intent nextIntent) {
105+
ComponentName target = nextIntent.getComponent();
106+
if (target == null) {
107+
target = nextIntent.resolveActivity(mSourceContext.getPackageManager());
108+
}
109+
if (target != null) {
110+
addParentStack(target);
111+
}
112+
addNextIntent(nextIntent);
113+
return this;
114+
}
115+
92116
/**
93117
* Add the activity parent chain as specified by the
94118
* {@link Activity#getParentActivityIntent() getParentActivityIntent()} method of the activity
@@ -200,25 +224,32 @@ public int getIntentCount() {
200224
}
201225

202226
/**
203-
* Get the intent at the specified index.
227+
* Return the intent at the specified index for modification.
204228
* Useful if you need to modify the flags or extras of an intent that was previously added,
205229
* for example with {@link #addParentStack(Activity)}.
206230
*
207231
* @param index Index from 0-getIntentCount()
208232
* @return the intent at position index
209233
*/
210-
public Intent getIntent(int index) {
234+
public Intent editIntentAt(int index) {
211235
return mIntents.get(index);
212236
}
213237

214-
public Iterator<Intent> iterator() {
215-
return mIntents.iterator();
238+
/**
239+
* Start the task stack constructed by this builder.
240+
*/
241+
public void startActivities() {
242+
startActivities(null);
216243
}
217244

218245
/**
219246
* Start the task stack constructed by this builder.
247+
*
248+
* @param options Additional options for how the Activity should be started.
249+
* See {@link android.content.Context#startActivity(Intent, Bundle)
250+
* Context.startActivity(Intent, Bundle)} for more details.
220251
*/
221-
public void startActivities() {
252+
public void startActivities(Bundle options) {
222253
if (mIntents.isEmpty()) {
223254
throw new IllegalStateException(
224255
"No intents added to TaskStackBuilder; cannot startActivities");
@@ -228,7 +259,7 @@ public void startActivities() {
228259
intents[0].addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
229260
Intent.FLAG_ACTIVITY_CLEAR_TASK |
230261
Intent.FLAG_ACTIVITY_TASK_ON_HOME);
231-
mSourceContext.startActivities(intents);
262+
mSourceContext.startActivities(intents, options);
232263
}
233264

234265
/**
@@ -240,9 +271,29 @@ public void startActivities() {
240271
* {@link PendingIntent#FLAG_UPDATE_CURRENT}, or any of the flags supported by
241272
* {@link Intent#fillIn(Intent, int)} to control which unspecified parts of the
242273
* intent that can be supplied when the actual send happens.
274+
*
243275
* @return The obtained PendingIntent
244276
*/
245277
public PendingIntent getPendingIntent(int requestCode, int flags) {
278+
return getPendingIntent(requestCode, flags, null);
279+
}
280+
281+
/**
282+
* Obtain a {@link PendingIntent} for launching the task constructed by this builder so far.
283+
*
284+
* @param requestCode Private request code for the sender
285+
* @param flags May be {@link PendingIntent#FLAG_ONE_SHOT},
286+
* {@link PendingIntent#FLAG_NO_CREATE}, {@link PendingIntent#FLAG_CANCEL_CURRENT},
287+
* {@link PendingIntent#FLAG_UPDATE_CURRENT}, or any of the flags supported by
288+
* {@link Intent#fillIn(Intent, int)} to control which unspecified parts of the
289+
* intent that can be supplied when the actual send happens.
290+
* @param options Additional options for how the Activity should be started.
291+
* See {@link android.content.Context#startActivity(Intent, Bundle)
292+
* Context.startActivity(Intent, Bundle)} for more details.
293+
*
294+
* @return The obtained PendingIntent
295+
*/
296+
public PendingIntent getPendingIntent(int requestCode, int flags, Bundle options) {
246297
if (mIntents.isEmpty()) {
247298
throw new IllegalStateException(
248299
"No intents added to TaskStackBuilder; cannot getPendingIntent");
@@ -252,6 +303,17 @@ public PendingIntent getPendingIntent(int requestCode, int flags) {
252303
intents[0].addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
253304
Intent.FLAG_ACTIVITY_CLEAR_TASK |
254305
Intent.FLAG_ACTIVITY_TASK_ON_HOME);
255-
return PendingIntent.getActivities(mSourceContext, requestCode, intents, flags);
306+
return PendingIntent.getActivities(mSourceContext, requestCode, intents, flags, options);
307+
}
308+
309+
/**
310+
* Return an array containing the intents added to this builder. The intent at the
311+
* root of the task stack will appear as the first item in the array and the
312+
* intent at the top of the stack will appear as the last item.
313+
*
314+
* @return An array containing the intents added to this builder.
315+
*/
316+
public Intent[] getIntents() {
317+
return mIntents.toArray(new Intent[mIntents.size()]);
256318
}
257319
}

0 commit comments

Comments
 (0)