Activity.StartActivityIfNeeded Method

Definition

Overloads

Name Description
StartActivityIfNeeded(Intent, Int32)

Same as calling startActivityIfNeeded(Intent,int,Bundle) with no options.

StartActivityIfNeeded(Intent, Int32, Bundle)

A special variation to launch an activity only if a new activity instance is needed to handle the given Intent.

StartActivityIfNeeded(Intent, Int32)

Same as calling startActivityIfNeeded(Intent,int,Bundle) with no options.

[Android.Runtime.Register("startActivityIfNeeded", "(Landroid/content/Intent;I)Z", "GetStartActivityIfNeeded_Landroid_content_Intent_IHandler")]
public virtual bool StartActivityIfNeeded(Android.Content.Intent intent, int requestCode);
[<Android.Runtime.Register("startActivityIfNeeded", "(Landroid/content/Intent;I)Z", "GetStartActivityIfNeeded_Landroid_content_Intent_IHandler")>]
abstract member StartActivityIfNeeded : Android.Content.Intent * int -> bool
override this.StartActivityIfNeeded : Android.Content.Intent * int -> bool

Parameters

intent
Intent

Intent: The intent to start. This value cannot be null.

requestCode
Int32

int: If >= 0, this code will be returned in onActivityResult() when the activity exits; If < 0, no result will return when the activity exits, as described in startActivityForResult(Intent, int).

Returns

If a new activity was launched then true is returned; otherwise false is returned and you must handle the Intent yourself.

Attributes

Remarks

Same as calling startActivityIfNeeded(Intent,int,Bundle) with no options.

See also:

Android reference for android.app.Activity.startActivityIfNeeded.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

StartActivityIfNeeded(Intent, Int32, Bundle)

A special variation to launch an activity only if a new activity instance is needed to handle the given Intent.

[Android.Runtime.Register("startActivityIfNeeded", "(Landroid/content/Intent;ILandroid/os/Bundle;)Z", "GetStartActivityIfNeeded_Landroid_content_Intent_ILandroid_os_Bundle_Handler")]
public virtual bool StartActivityIfNeeded(Android.Content.Intent intent, int requestCode, Android.OS.Bundle? options);
[<Android.Runtime.Register("startActivityIfNeeded", "(Landroid/content/Intent;ILandroid/os/Bundle;)Z", "GetStartActivityIfNeeded_Landroid_content_Intent_ILandroid_os_Bundle_Handler")>]
abstract member StartActivityIfNeeded : Android.Content.Intent * int * Android.OS.Bundle -> bool
override this.StartActivityIfNeeded : Android.Content.Intent * int * Android.OS.Bundle -> bool

Parameters

intent
Intent

Intent: The intent to start. This value cannot be null.

requestCode
Int32

int: If >= 0, this code will be returned in onActivityResult() when the activity exits; If < 0, no result will return when the activity exits, as described in startActivityForResult(Intent, int).

options
Bundle

Bundle: Additional options for how the Activity should be started. See android.content.Context.startActivity(Intent,Bundle) Context.startActivity(Intent, Bundle)} for more details. This value may be null.

Returns

If a new activity was launched then true is returned; otherwise false is returned and you must handle the Intent yourself.

Attributes

Remarks

A special variation to launch an activity only if a new activity instance is needed to handle the given Intent. In other words, this is just like startActivityForResult(Intent,int) except: if you are using the Intent.FLAG_ACTIVITY_SINGLE_TOP flag, or singleTask or singleTop launchMode, and the activity that handles intent is the same as your currently running activity, then a new instance is not needed. In this case, instead of the normal behavior of calling onNewIntent(Intent) this function will return and you can handle the Intent yourself. This function can only be called from a top-level activity; if it is called from a child activity, a runtime exception will be thrown.

See also:

Android reference for android.app.Activity.startActivityIfNeeded.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to