Únete a ⁠ #Android11: The Beta Launch Show el 3 de junio.

ActivityResultContract

public abstract class ActivityResultContract
extends Object

java.lang.Object
   ↳ androidx.activity.result.contract.ActivityResultContract<I, O>


A contract specifying that an activity can be called with an input of type I and produce an output of type O Makes calling an activity for result type-safe.

Summary

Nested classes

class ActivityResultContract.SynchronousResult<T>

The wrapper for a result provided in ActivityResultContract.getSynchronousResult(Context, I) 

Public constructors

ActivityResultContract()

Public methods

abstract Intent createIntent(Context context, I input)

Create an intent that can be used for Activity.startActivityForResult(Intent, int)

SynchronousResult<O> getSynchronousResult(Context context, I input)

An optional method you can implement that can be used to potentially provide a result in lieu of starting an activity.

abstract O parseResult(int resultCode, Intent intent)

Convert result obtained from Activity.onActivityResult(int, int, Intent) to O

Inherited methods

Public constructors

ActivityResultContract

public ActivityResultContract ()

Public methods

createIntent

public abstract Intent createIntent (Context context, 
                I input)

Create an intent that can be used for Activity.startActivityForResult(Intent, int)

Parameters
context Context

input I

Returns
Intent

getSynchronousResult

public SynchronousResult<O> getSynchronousResult (Context context, 
                I input)

An optional method you can implement that can be used to potentially provide a result in lieu of starting an activity.

Parameters
context Context

input I

Returns
SynchronousResult<O> the result wrapped in a ActivityResultContract.SynchronousResult or null if the call should proceed to start an activity.

parseResult

public abstract O parseResult (int resultCode, 
                Intent intent)

Convert result obtained from Activity.onActivityResult(int, int, Intent) to O

Parameters
resultCode int

intent Intent

Returns
O