AppFunctionManager.RegisterAppFunction 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
註冊一個應用程式函式的執行時實作,該函式可使用 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
參數
- functionIdentifier
- String
函式的唯一識別碼,必須與應用程式 XML 資源宣告中的條目相符。 這個值不可能為零值。
- executor
- IExecutor
執行者將被調用該功能。 這個值不可能為零值。
- appFunction
- IAppFunction
AppFunction 實作在函式被觸發時執行。 這個值不可能為零值。
傳回
一個可以用來取消註冊函式的 AppFunctionRegistration 物件。 這個值不可能為零值。
- 屬性
備註
註冊一個應用程式函式的執行時實作,該函式可使用 executeAppFunction(AppInteractionSession, ExecuteAppFunctionRequest, Executor, CancellationSignal, OutcomeReceiver) 執行。
針對此方法提供的應用程式函式的 executeAppFunction(AppInteractionSession, ExecuteAppFunctionRequest, Executor, CancellationSignal, OutcomeReceiver) 會觸發該實作的 AppFunction.onExecuteAppFunction 方法,只要註冊程序未凍結,且註冊該函式的上下文未被摧毀(此時註冊將被移除)。
你必須在 AndroidManifest.xml 中宣告應用程式函式,使用名為 android.app.appfunctions 的應用程式層 <級屬性> 。 有關 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 實作已註冊,系統就會強烈參考所提供的 AppFunction 實作。 為了防止記憶體洩漏並確保系統知道該函式不再可用,當函式不再相關時,你必須明確呼叫 AppFunctionRegistration.unregister(例如 在 Activity.onStop() 或在 Service.stopForeground(boolean)之前)。
Android 參考資料。android.app.appfunctions.AppFunctionManager.registerAppFunction
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。