Compartir a través de


Activity.StartActivityIfNeeded Method

Definition

Overloads

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

The intent to start.

requestCode
Int32

If >= 0, this code will be returned in onActivityResult() when the activity exits, as described in #startActivityForResult.

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.

Java documentation for android.app.Activity.startActivityIfNeeded(android.content.Intent, int).

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.

See also

  • <xref:Android.App.Activity.StartActivityForResult(Android.Content.Intent%2c+System.Int32)>

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

The intent to start.

requestCode
Int32

If >= 0, this code will be returned in onActivityResult() when the activity exits, as described in #startActivityForResult.

options
Bundle

Additional options for how the Activity should be started. See android.content.Context#startActivity(Intent, Bundle) Context.startActivity(Intent, Bundle)} for more details.

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 android.R.styleable#AndroidManifestActivity_launchMode launchMode, and the activity that handles <var>intent</var> 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 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.

Java documentation for android.app.Activity.startActivityIfNeeded(android.content.Intent, int, android.os.Bundle).

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.

See also

  • <xref:Android.App.Activity.StartActivityForResult(Android.Content.Intent%2c+System.Int32)>

Applies to