diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 2de205b409703..723204f35e950 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -846,8 +846,9 @@ class ContextImpl extends Context { // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is // generally not allowed, except if the caller specifies the task id the activity should // be launched in. - if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0 - && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) { + if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == 0 + && (options == null + || ActivityOptions.fromBundle(options).getLaunchTaskId() == -1)) { throw new AndroidRuntimeException( "Calling startActivity() from outside of an Activity " + " context requires the FLAG_ACTIVITY_NEW_TASK flag."