语言

AppFunctionManager.RegisterAppFunction 方法

定义

为应用函数注册运行时实现,该实现可以使用 executeAppFunction(AppInteractionSession、ExecuteAppFunctionRequest、Executor、CancellationSignal、ResultReceiver)执行。

[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

参数

functionIdentifier
String

函数的唯一标识符,该标识符必须与应用的 XML 资源声明中的条目匹配。 此值不能为 null。

executor
IExecutor

将对其调用函数的执行程序。 此值不能为 null。

appFunction
IAppFunction

触发函数时要执行的 AppFunction 实现。 此值不能为 null。

返回

可用于注销函数的 AppFunctionRegistration 对象。 此值不能为 null。

特性

注解

为应用函数注册运行时实现,该实现可以使用 executeAppFunction(AppInteractionSession、ExecuteAppFunctionRequest、Executor、CancellationSignal、ResultReceiver)执行。

executeAppFunction(AppInteractionSession、ExecuteAppFunctionRequest、Executor、CancellationSignal、ResultReceiver)面向此方法提供的应用函数,将触发所提供的实现的 AppFunction.onExecuteAppFunction 方法,前提是注册过程未冻结,并且不会销毁注册的上下文(此时将删除注册)。

必须使用名为 android.app.appfunctions 的应用程序级别 <属性> 在 AndroidManifest.xml 中声明应用函数。 有关 XML 架构的详细信息,请参阅 AppFunctionMetadata(以下示例中的your_app_functions.xml)。

<application ...>
<property
      android:name="android.app.appfunctions"
      android:value="your_app_functions.xml" />
  ...
</application>

函数实现只能从活动或服务上下文注册。 如果从活动注册,强烈建议为函数定义AppFunctionMetadata.SCOPE_ACTIVITY。

functionIdentifier 必须与应用的应用程序级 XML 资产中声明的应用函数相对应。 如果未找到标识符,此方法将引发 IllegalArgumentException。 尝试根据 AppFunctionMetadata.getScope 的规则注册重复函数将引发 IllegalStateException。

若要一次性注册多个函数,请考虑使用 registerAppFunctions(List)作为更高效的替代方法。

只要系统已注册,系统就具有对提供的 AppFunction 实现的强烈引用。 若要防止内存泄漏并确保系统知道该函数不再可用,必须在函数不再相关(例如,Activity.onStop()或 Service.stopForeground(boolean)之前显式调用 AppFunctionRegistration.unregister。

Android 参考。android.app.appfunctions.AppFunctionManager.registerAppFunction

本页的某些部分是根据 Android 开放源代码项目创建和共享的工作进行的修改,并根据 Creative Commons 2.5 属性许可证中所述的术语使用。

适用于