AppFunctionManager.RegisterAppFunction Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Registers a runtime implementation for an app function, that can be executed using executeAppFunction(AppInteractionSession, ExecuteAppFunctionRequest, Executor, CancellationSignal, OutcomeReceiver).
[Android.Runtime.Register("registerAppFunction", "(Ljava/lang/String;Ljava/util/concurrent/Executor;Landroid/app/appfunctions/AppFunction;)Landroid/app/appfunctions/AppFunctionRegistration;", "", ApiSince=37)]
public Android.App.AppFunctions.IAppFunctionRegistration RegisterAppFunction(string functionIdentifier, Java.Util.Concurrent.IExecutor executor, Android.App.AppFunctions.IAppFunction appFunction);
[<Android.Runtime.Register("registerAppFunction", "(Ljava/lang/String;Ljava/util/concurrent/Executor;Landroid/app/appfunctions/AppFunction;)Landroid/app/appfunctions/AppFunctionRegistration;", "", ApiSince=37)>]
member this.RegisterAppFunction : string * Java.Util.Concurrent.IExecutor * Android.App.AppFunctions.IAppFunction -> Android.App.AppFunctions.IAppFunctionRegistration
Parameters
- functionIdentifier
- String
The unique identifier for the function, which must match an entry in the app's XML resource declarations. This value cannot be null.
- executor
- IExecutor
The Executor on which the function will be invoked. This value cannot be null.
- appFunction
- IAppFunction
The AppFunction implementation to be executed when the function is triggered. This value cannot be null.
Returns
A AppFunctionRegistration object that can be used to unregister the function. This value cannot be null.
- Attributes
Remarks
Registers a runtime implementation for an app function, that can be executed using executeAppFunction(AppInteractionSession, ExecuteAppFunctionRequest, Executor, CancellationSignal, OutcomeReceiver).
executeAppFunction(AppInteractionSession, ExecuteAppFunctionRequest, Executor, CancellationSignal, OutcomeReceiver) targeting an app function provided by this method will trigger the AppFunction.onExecuteAppFunction method of the provided implementation, as long as the process registering it is not frozen, and the Context registering it is not destroyed (at which point the registration will be removed).
You must declare the app function in your AndroidManifest.xml using an application-level <property> named android.app.appfunctions. See AppFunctionMetadata for details on the XML schema (your_app_functions.xml in the example below).
<application ...>
<property
android:name="android.app.appfunctions"
android:value="your_app_functions.xml" />
...
</application>
Function implementations can only be registered from Activity or Service contexts. If registering from an Activity, strongly consider AppFunctionMetadata.SCOPE_ACTIVITY for your function definition.
The functionIdentifier must correspond to an app function declared in your app's application-level XML assets. If the identifier is not found, this method will throw an IllegalArgumentException. Attempting to register a duplicate function based on the rules of AppFunctionMetadata.getScope will throw an IllegalStateException.
To register multiple functions at once, consider using registerAppFunctions(List) as a more efficient alternative.
The system holds a strong reference to the provided AppFunction implementation as long as it is registered. To prevent memory leaks and ensure the system is aware that the function is no longer available, you must explicitly call AppFunctionRegistration.unregister when the function is no longer relevant (e.g., in Activity.onStop() or before Service.stopForeground(boolean)).
Android reference for android.app.appfunctions.AppFunctionManager.registerAppFunction.
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.