Skip to content

Commit 49a22f2

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "TaskStackBuilder correctness fixes" into jb-mr1-dev
2 parents a8a402f + 75e0af8 commit 49a22f2

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

core/java/android/app/TaskStackBuilder.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,7 @@ public void startActivities(Bundle options) {
216216
"No intents added to TaskStackBuilder; cannot startActivities");
217217
}
218218

219-
Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
220-
intents[0].addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
221-
Intent.FLAG_ACTIVITY_CLEAR_TASK |
222-
Intent.FLAG_ACTIVITY_TASK_ON_HOME);
223-
mSourceContext.startActivities(intents, options);
219+
mSourceContext.startActivities(getIntents(), options);
224220
}
225221

226222
/**
@@ -260,11 +256,8 @@ public PendingIntent getPendingIntent(int requestCode, int flags, Bundle options
260256
"No intents added to TaskStackBuilder; cannot getPendingIntent");
261257
}
262258

263-
Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
264-
intents[0].addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
265-
Intent.FLAG_ACTIVITY_CLEAR_TASK |
266-
Intent.FLAG_ACTIVITY_TASK_ON_HOME);
267-
return PendingIntent.getActivities(mSourceContext, requestCode, intents, flags, options);
259+
return PendingIntent.getActivities(mSourceContext, requestCode, getIntents(),
260+
flags, options);
268261
}
269262

270263
/**
@@ -275,6 +268,15 @@ public PendingIntent getPendingIntent(int requestCode, int flags, Bundle options
275268
* @return An array containing the intents added to this builder.
276269
*/
277270
public Intent[] getIntents() {
278-
return mIntents.toArray(new Intent[mIntents.size()]);
271+
Intent[] intents = new Intent[mIntents.size()];
272+
if (intents.length == 0) return intents;
273+
274+
intents[0] = new Intent(mIntents.get(0)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
275+
Intent.FLAG_ACTIVITY_CLEAR_TASK |
276+
Intent.FLAG_ACTIVITY_TASK_ON_HOME);
277+
for (int i = 1; i < intents.length; i++) {
278+
intents[i] = new Intent(mIntents.get(i));
279+
}
280+
return intents;
279281
}
280282
}

0 commit comments

Comments
 (0)