Skip to content

Commit f1bdf65

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Start using the new activity options argument."
2 parents ac0f18d + 7a2195c commit f1bdf65

File tree

11 files changed

+220
-35
lines changed

11 files changed

+220
-35
lines changed

api/current.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,6 +2864,12 @@ package android.app {
28642864
field public android.content.ComponentName topActivity;
28652865
}
28662866

2867+
public class ActivityOptions {
2868+
method public void join(android.app.ActivityOptions);
2869+
method public static android.app.ActivityOptions makeCustomAnimation(android.content.Context, int, int);
2870+
method public android.os.Bundle toBundle();
2871+
}
2872+
28672873
public class AlarmManager {
28682874
method public void cancel(android.app.PendingIntent);
28692875
method public void set(int, long, android.app.PendingIntent);
@@ -3728,7 +3734,9 @@ package android.app {
37283734
method public void cancel();
37293735
method public int describeContents();
37303736
method public static android.app.PendingIntent getActivities(android.content.Context, int, android.content.Intent[], int);
3737+
method public static android.app.PendingIntent getActivities(android.content.Context, int, android.content.Intent[], int, android.os.Bundle);
37313738
method public static android.app.PendingIntent getActivity(android.content.Context, int, android.content.Intent, int);
3739+
method public static android.app.PendingIntent getActivity(android.content.Context, int, android.content.Intent, int, android.os.Bundle);
37323740
method public static android.app.PendingIntent getBroadcast(android.content.Context, int, android.content.Intent, int);
37333741
method public android.content.IntentSender getIntentSender();
37343742
method public static android.app.PendingIntent getService(android.content.Context, int, android.content.Intent, int);

core/java/android/app/Activity.java

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import android.content.res.Configuration;
3333
import android.content.res.Resources;
3434
import android.content.res.TypedArray;
35-
import android.content.res.Resources.Theme;
3635
import android.database.Cursor;
3736
import android.graphics.Bitmap;
3837
import android.graphics.Canvas;
@@ -55,7 +54,6 @@
5554
import android.util.EventLog;
5655
import android.util.Log;
5756
import android.util.SparseArray;
58-
import android.util.TypedValue;
5957
import android.view.ActionMode;
6058
import android.view.ContextMenu;
6159
import android.view.ContextMenu.ContextMenuInfo;
@@ -3208,7 +3206,8 @@ public void startActivityForResult(Intent intent, int requestCode) {
32083206
* @param requestCode If >= 0, this code will be returned in
32093207
* onActivityResult() when the activity exits.
32103208
* @param options Additional options for how the Activity should be started.
3211-
* May be null if there are no options.
3209+
* See {@link android.content.Context#startActivity(Intent, Bundle)
3210+
* Context.startActivity(Intent, Bundle)} for more details.
32123211
*
32133212
* @throws android.content.ActivityNotFoundException
32143213
*
@@ -3288,7 +3287,10 @@ public void startIntentSenderForResult(IntentSender intent, int requestCode,
32883287
* <var>flagsMask</var>
32893288
* @param extraFlags Always set to 0.
32903289
* @param options Additional options for how the Activity should be started.
3291-
* May be null if there are no options.
3290+
* See {@link android.content.Context#startActivity(Intent, Bundle)
3291+
* Context.startActivity(Intent, Bundle)} for more details. If options
3292+
* have also been supplied by the IntentSender, options given here will
3293+
* override any that conflict with those given by the IntentSender.
32923294
*/
32933295
public void startIntentSenderForResult(IntentSender intent, int requestCode,
32943296
Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
@@ -3369,7 +3371,8 @@ public void startActivity(Intent intent) {
33693371
*
33703372
* @param intent The intent to start.
33713373
* @param options Additional options for how the Activity should be started.
3372-
* May be null if there are no options.
3374+
* See {@link android.content.Context#startActivity(Intent, Bundle)
3375+
* Context.startActivity(Intent, Bundle)} for more details.
33733376
*
33743377
* @throws android.content.ActivityNotFoundException
33753378
*
@@ -3417,7 +3420,8 @@ public void startActivities(Intent[] intents) {
34173420
*
34183421
* @param intents The intents to start.
34193422
* @param options Additional options for how the Activity should be started.
3420-
* May be null if there are no options.
3423+
* See {@link android.content.Context#startActivity(Intent, Bundle)
3424+
* Context.startActivity(Intent, Bundle)} for more details.
34213425
*
34223426
* @throws android.content.ActivityNotFoundException
34233427
*
@@ -3465,7 +3469,10 @@ public void startIntentSender(IntentSender intent,
34653469
* <var>flagsMask</var>
34663470
* @param extraFlags Always set to 0.
34673471
* @param options Additional options for how the Activity should be started.
3468-
* May be null if there are no options.
3472+
* See {@link android.content.Context#startActivity(Intent, Bundle)
3473+
* Context.startActivity(Intent, Bundle)} for more details. If options
3474+
* have also been supplied by the IntentSender, options given here will
3475+
* override any that conflict with those given by the IntentSender.
34693476
*/
34703477
public void startIntentSender(IntentSender intent,
34713478
Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
@@ -3521,7 +3528,8 @@ public boolean startActivityIfNeeded(Intent intent, int requestCode) {
35213528
* onActivityResult() when the activity exits, as described in
35223529
* {@link #startActivityForResult}.
35233530
* @param options Additional options for how the Activity should be started.
3524-
* May be null if there are no options.
3531+
* See {@link android.content.Context#startActivity(Intent, Bundle)
3532+
* Context.startActivity(Intent, Bundle)} for more details.
35253533
*
35263534
* @return If a new activity was launched then true is returned; otherwise
35273535
* false is returned and you must handle the Intent yourself.
@@ -3592,7 +3600,8 @@ public boolean startNextMatchingActivity(Intent intent) {
35923600
* your own activity; the only changes you can make are to the extras
35933601
* inside of it.
35943602
* @param options Additional options for how the Activity should be started.
3595-
* May be null if there are no options.
3603+
* See {@link android.content.Context#startActivity(Intent, Bundle)
3604+
* Context.startActivity(Intent, Bundle)} for more details.
35963605
*
35973606
* @return Returns a boolean indicating whether there was another Activity
35983607
* to start: true if there was a next activity to start, false if there
@@ -3644,7 +3653,8 @@ public void startActivityFromChild(Activity child, Intent intent,
36443653
* @param intent The intent to start.
36453654
* @param requestCode Reply request code. < 0 if reply is not requested.
36463655
* @param options Additional options for how the Activity should be started.
3647-
* May be null if there are no options.
3656+
* See {@link android.content.Context#startActivity(Intent, Bundle)
3657+
* Context.startActivity(Intent, Bundle)} for more details.
36483658
*
36493659
* @throws android.content.ActivityNotFoundException
36503660
*
@@ -3694,7 +3704,8 @@ public void startActivityFromFragment(Fragment fragment, Intent intent,
36943704
* @param intent The intent to start.
36953705
* @param requestCode Reply request code. < 0 if reply is not requested.
36963706
* @param options Additional options for how the Activity should be started.
3697-
* May be null if there are no options.
3707+
* See {@link android.content.Context#startActivity(Intent, Bundle)
3708+
* Context.startActivity(Intent, Bundle)} for more details.
36983709
*
36993710
* @throws android.content.ActivityNotFoundException
37003711
*
@@ -3744,6 +3755,14 @@ public void startIntentSenderFromChild(Activity child, IntentSender intent,
37443755
* Call immediately after one of the flavors of {@link #startActivity(Intent)}
37453756
* or {@link #finish} to specify an explicit transition animation to
37463757
* perform next.
3758+
*
3759+
* <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN} an alternative
3760+
* to using this with starting activities is to supply the desired animation
3761+
* information through a {@link ActivityOptions} bundle to
3762+
* {@link #startActivity(Intent, Bundle) or a related function. This allows
3763+
* you to specify a custom animation even when starting an activity from
3764+
* outside the context of the current top activity.
3765+
*
37473766
* @param enterAnim A resource ID of the animation resource to use for
37483767
* the incoming activity. Use 0 for no animation.
37493768
* @param exitAnim A resource ID of the animation resource to use for
@@ -4065,7 +4084,7 @@ public PendingIntent createPendingResult(int requestCode, Intent data,
40654084
ActivityManagerNative.getDefault().getIntentSender(
40664085
ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName,
40674086
mParent == null ? mToken : mParent.mToken,
4068-
mEmbeddedID, requestCode, new Intent[] { data }, null, flags);
4087+
mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null);
40694088
return target != null ? new PendingIntent(target) : null;
40704089
} catch (RemoteException e) {
40714090
// Empty

core/java/android/app/ActivityManagerNative.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,9 +835,11 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
835835
requestResolvedTypes = null;
836836
}
837837
int fl = data.readInt();
838+
Bundle options = data.readInt() != 0
839+
? Bundle.CREATOR.createFromParcel(data) : null;
838840
IIntentSender res = getIntentSender(type, packageName, token,
839841
resultWho, requestCode, requestIntents,
840-
requestResolvedTypes, fl);
842+
requestResolvedTypes, fl, options);
841843
reply.writeNoException();
842844
reply.writeStrongBinder(res != null ? res.asBinder() : null);
843845
return true;
@@ -2607,8 +2609,8 @@ public String getPackageForToken(IBinder token) throws RemoteException
26072609
}
26082610
public IIntentSender getIntentSender(int type,
26092611
String packageName, IBinder token, String resultWho,
2610-
int requestCode, Intent[] intents, String[] resolvedTypes, int flags)
2611-
throws RemoteException {
2612+
int requestCode, Intent[] intents, String[] resolvedTypes, int flags,
2613+
Bundle options) throws RemoteException {
26122614
Parcel data = Parcel.obtain();
26132615
Parcel reply = Parcel.obtain();
26142616
data.writeInterfaceToken(IActivityManager.descriptor);
@@ -2625,6 +2627,12 @@ public IIntentSender getIntentSender(int type,
26252627
data.writeInt(0);
26262628
}
26272629
data.writeInt(flags);
2630+
if (options != null) {
2631+
data.writeInt(1);
2632+
options.writeToParcel(data, 0);
2633+
} else {
2634+
data.writeInt(0);
2635+
}
26282636
mRemote.transact(GET_INTENT_SENDER_TRANSACTION, data, reply, 0);
26292637
reply.readException();
26302638
IIntentSender res = IIntentSender.Stub.asInterface(

core/java/android/app/Fragment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,8 @@ public LoaderManager getLoaderManager() {
965965
/**
966966
* Call {@link Activity#startActivity(Intent)} on the fragment's
967967
* containing Activity.
968+
*
969+
* @param intent The intent to start.
968970
*/
969971
public void startActivity(Intent intent) {
970972
startActivity(intent, null);
@@ -973,6 +975,11 @@ public void startActivity(Intent intent) {
973975
/**
974976
* Call {@link Activity#startActivity(Intent, Bundle)} on the fragment's
975977
* containing Activity.
978+
*
979+
* @param intent The intent to start.
980+
* @param options Additional options for how the Activity should be started.
981+
* See {@link android.content.Context#startActivity(Intent, Bundle)
982+
* Context.startActivity(Intent, Bundle)} for more details.
976983
*/
977984
public void startActivity(Intent intent, Bundle options) {
978985
if (mActivity == null) {

core/java/android/app/IActivityManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void setRequestedOrientation(IBinder token,
169169
public IIntentSender getIntentSender(int type,
170170
String packageName, IBinder token, String resultWho,
171171
int requestCode, Intent[] intents, String[] resolvedTypes,
172-
int flags) throws RemoteException;
172+
int flags, Bundle options) throws RemoteException;
173173
public void cancelIntentSender(IIntentSender sender) throws RemoteException;
174174
public boolean clearApplicationUserData(final String packageName,
175175
final IPackageDataObserver observer, int userId) throws RemoteException;

core/java/android/app/PendingIntent.java

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,35 @@ public void run() {
188188
*/
189189
public static PendingIntent getActivity(Context context, int requestCode,
190190
Intent intent, int flags) {
191+
return getActivity(context, requestCode, intent, flags, null);
192+
}
193+
194+
/**
195+
* Retrieve a PendingIntent that will start a new activity, like calling
196+
* {@link Context#startActivity(Intent) Context.startActivity(Intent)}.
197+
* Note that the activity will be started outside of the context of an
198+
* existing activity, so you must use the {@link Intent#FLAG_ACTIVITY_NEW_TASK
199+
* Intent.FLAG_ACTIVITY_NEW_TASK} launch flag in the Intent.
200+
*
201+
* @param context The Context in which this PendingIntent should start
202+
* the activity.
203+
* @param requestCode Private request code for the sender (currently
204+
* not used).
205+
* @param intent Intent of the activity to be launched.
206+
* @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
207+
* {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
208+
* or any of the flags as supported by
209+
* {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
210+
* of the intent that can be supplied when the actual send happens.
211+
* @param options Additional options for how the Activity should be started.
212+
* May be null if there are no options.
213+
*
214+
* @return Returns an existing or new PendingIntent matching the given
215+
* parameters. May return null only if {@link #FLAG_NO_CREATE} has been
216+
* supplied.
217+
*/
218+
public static PendingIntent getActivity(Context context, int requestCode,
219+
Intent intent, int flags, Bundle options) {
191220
String packageName = context.getPackageName();
192221
String resolvedType = intent != null ? intent.resolveTypeIfNeeded(
193222
context.getContentResolver()) : null;
@@ -197,7 +226,8 @@ public static PendingIntent getActivity(Context context, int requestCode,
197226
ActivityManagerNative.getDefault().getIntentSender(
198227
ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
199228
null, null, requestCode, new Intent[] { intent },
200-
resolvedType != null ? new String[] { resolvedType } : null, flags);
229+
resolvedType != null ? new String[] { resolvedType } : null,
230+
flags, options);
201231
return target != null ? new PendingIntent(target) : null;
202232
} catch (RemoteException e) {
203233
}
@@ -247,6 +277,52 @@ public static PendingIntent getActivity(Context context, int requestCode,
247277
*/
248278
public static PendingIntent getActivities(Context context, int requestCode,
249279
Intent[] intents, int flags) {
280+
return getActivities(context, requestCode, intents, flags, null);
281+
}
282+
283+
/**
284+
* Like {@link #getActivity(Context, int, Intent, int)}, but allows an
285+
* array of Intents to be supplied. The first Intent in the array is
286+
* taken as the primary key for the PendingIntent, like the single Intent
287+
* given to {@link #getActivity(Context, int, Intent, int)}. Upon sending
288+
* the resulting PendingIntent, all of the Intents are started in the same
289+
* way as they would be by passing them to {@link Context#startActivities(Intent[])}.
290+
*
291+
* <p class="note">
292+
* The <em>first</em> intent in the array will be started outside of the context of an
293+
* existing activity, so you must use the {@link Intent#FLAG_ACTIVITY_NEW_TASK
294+
* Intent.FLAG_ACTIVITY_NEW_TASK} launch flag in the Intent. (Activities after
295+
* the first in the array are started in the context of the previous activity
296+
* in the array, so FLAG_ACTIVITY_NEW_TASK is not needed nor desired for them.)
297+
* </p>
298+
*
299+
* <p class="note">
300+
* The <em>last</em> intent in the array represents the key for the
301+
* PendingIntent. In other words, it is the significant element for matching
302+
* (as done with the single intent given to {@link #getActivity(Context, int, Intent, int)},
303+
* its content will be the subject of replacement by
304+
* {@link #send(Context, int, Intent)} and {@link #FLAG_UPDATE_CURRENT}, etc.
305+
* This is because it is the most specific of the supplied intents, and the
306+
* UI the user actually sees when the intents are started.
307+
* </p>
308+
*
309+
* @param context The Context in which this PendingIntent should start
310+
* the activity.
311+
* @param requestCode Private request code for the sender (currently
312+
* not used).
313+
* @param intents Array of Intents of the activities to be launched.
314+
* @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE},
315+
* {@link #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT},
316+
* or any of the flags as supported by
317+
* {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts
318+
* of the intent that can be supplied when the actual send happens.
319+
*
320+
* @return Returns an existing or new PendingIntent matching the given
321+
* parameters. May return null only if {@link #FLAG_NO_CREATE} has been
322+
* supplied.
323+
*/
324+
public static PendingIntent getActivities(Context context, int requestCode,
325+
Intent[] intents, int flags, Bundle options) {
250326
String packageName = context.getPackageName();
251327
String[] resolvedTypes = new String[intents.length];
252328
for (int i=0; i<intents.length; i++) {
@@ -257,7 +333,7 @@ public static PendingIntent getActivities(Context context, int requestCode,
257333
IIntentSender target =
258334
ActivityManagerNative.getDefault().getIntentSender(
259335
ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
260-
null, null, requestCode, intents, resolvedTypes, flags);
336+
null, null, requestCode, intents, resolvedTypes, flags, options);
261337
return target != null ? new PendingIntent(target) : null;
262338
} catch (RemoteException e) {
263339
}
@@ -294,7 +370,8 @@ public static PendingIntent getBroadcast(Context context, int requestCode,
294370
ActivityManagerNative.getDefault().getIntentSender(
295371
ActivityManager.INTENT_SENDER_BROADCAST, packageName,
296372
null, null, requestCode, new Intent[] { intent },
297-
resolvedType != null ? new String[] { resolvedType } : null, flags);
373+
resolvedType != null ? new String[] { resolvedType } : null,
374+
flags, null);
298375
return target != null ? new PendingIntent(target) : null;
299376
} catch (RemoteException e) {
300377
}
@@ -332,7 +409,8 @@ public static PendingIntent getService(Context context, int requestCode,
332409
ActivityManagerNative.getDefault().getIntentSender(
333410
ActivityManager.INTENT_SENDER_SERVICE, packageName,
334411
null, null, requestCode, new Intent[] { intent },
335-
resolvedType != null ? new String[] { resolvedType } : null, flags);
412+
resolvedType != null ? new String[] { resolvedType } : null,
413+
flags, null);
336414
return target != null ? new PendingIntent(target) : null;
337415
} catch (RemoteException e) {
338416
}

0 commit comments

Comments
 (0)