語言

Context.BindService 方法

定義

多載

名稱 Description
BindService(Intent, IServiceConnection, Bind)

連接應用程式服務,必要時建立服務。

BindService(Intent, IServiceConnection, Context+BindServiceFlags)

請參見 bindService(Intent, ServiceConnection, int) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

BindService(Intent, Bind, IExecutor, IServiceConnection)

#bindService(Intent, ServiceConnection, int) bindService(Intent, ServiceConnection, int) 執行器一樣,用來控制 ServiceConnection 回調。

BindService(Intent, Context+BindServiceFlags, IExecutor, IServiceConnection)

請參見 bindService(Intent, int, Executor, ServiceConnection) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

BindService(Intent, IServiceConnection, Bind)

連接應用程式服務,必要時建立服務。

[Android.Runtime.Register("bindService", "(Landroid/content/Intent;Landroid/content/ServiceConnection;I)Z", "GetBindService_Landroid_content_Intent_Landroid_content_ServiceConnection_IHandler")]
public abstract bool BindService(Android.Content.Intent service, Android.Content.IServiceConnection conn, Android.Content.Bind flags);
[<Android.Runtime.Register("bindService", "(Landroid/content/Intent;Landroid/content/ServiceConnection;I)Z", "GetBindService_Landroid_content_Intent_Landroid_content_ServiceConnection_IHandler")>]
abstract member BindService : Android.Content.Intent * Android.Content.IServiceConnection * Android.Content.Bind -> bool

參數

service
Intent

識別要連接的服務。 意圖必須明確指定一個元件名稱。

conn
IServiceConnection

服務開始與停止時會接收資訊。 此物件必須是有效的 ServiceConnection 物件;它不能是無效的。

flags
Bind

綁定的操作選項。 可能是:<ul><li>0 <li>#BIND_AUTO_CREATE<li>#BIND_DEBUG_UNBIND<li>#BIND_NOT_FOREGROUND<li>#BIND_ABOVE_CLIENT<li>#BIND_ALLOW_OOM_MANAGEMENT<>#BIND_WAIVE_PRIORITY<>#BIND_IMPORTANT<>#BIND_ADJUST_WITH_ACTIVITY<>#BIND_NOT_PERCEPTIBLE<>#BIND_INCLUDE_CAPABILITIES</ul>

傳回

true 如果系統正在調出客戶有權限綁定的服務; false 如果系統找不到該服務,或是你的客戶端沒有綁定權限。 不論回傳值如何,你之後都應該呼叫 #unbindService 以解除連線。

屬性

例外狀況

備註

連接應用程式服務,必要時建立服務。 這定義了你的應用程式與服務之間的相依關係。 給定 <的 var>conn</var> 在建立服務物件時會收到該服務物件,並被告知它是否當機並重新啟動。 系統只會在呼叫上下文存在期間視為該服務的必要條件。 例如,若此情境為已停止的活動,服務在活動恢復前無需繼續運行。

若服務不支援綁定,則可從其null方法返回android.app.Service#onBind(Intent) onBind()。 如果有,則會呼叫 ServiceConnection 的方法 ServiceConnection#onNullBinding(ComponentName) onNullBinding() 而非 ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()

<b>註:</b> 此方法<>無法<>/em 從元件中BroadcastReceiver呼叫。 你可以用 BroadcastReceiver 與服務之間的溝通模式,是用包含要傳送指令的參數呼叫 #startService ,服務執行該指令後再呼叫其 android.app.Service#stopSelf(int) 方法。 請參考 API 示範中的 App/Service/Service Starting Arguments Controller 示範說明。 然而,從已註冊於 #registerReceiver的廣播接收器使用此方法是可以的,因為該廣播接收器的存續時間綁定於另一個物件(即註冊它的對象)。

此方法僅接受整數型標示,若要傳遞長型標標,則改為呼叫 #bindService(Intent, ServiceConnection, BindServiceFlags)

Java 文件 android.content.Context.bindService(android.content.Intent, android.content.ServiceConnection, int)

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

另請參閱

適用於

BindService(Intent, IServiceConnection, Context+BindServiceFlags)

請參見 bindService(Intent, ServiceConnection, int) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

[Android.Runtime.Register("bindService", "(Landroid/content/Intent;Landroid/content/ServiceConnection;Landroid/content/Context$BindServiceFlags;)Z", "GetBindService_Landroid_content_Intent_Landroid_content_ServiceConnection_Landroid_content_Context_BindServiceFlags_Handler", ApiSince=34)]
public virtual bool BindService(Android.Content.Intent service, Android.Content.IServiceConnection conn, Android.Content.Context.BindServiceFlags flags);
[<Android.Runtime.Register("bindService", "(Landroid/content/Intent;Landroid/content/ServiceConnection;Landroid/content/Context$BindServiceFlags;)Z", "GetBindService_Landroid_content_Intent_Landroid_content_ServiceConnection_Landroid_content_Context_BindServiceFlags_Handler", ApiSince=34)>]
abstract member BindService : Android.Content.Intent * Android.Content.IServiceConnection * Android.Content.Context.BindServiceFlags -> bool
override this.BindService : Android.Content.Intent * Android.Content.IServiceConnection * Android.Content.Context.BindServiceFlags -> bool

參數

service
Intent

此值不可能是空值。

conn
IServiceConnection

此值不可能是空值。

flags
Context.BindServiceFlags

此值不可能是空值。

傳回

請參見 bindService(Intent, ServiceConnection, int) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

屬性

備註

請參見 bindService(Intent, ServiceConnection, int) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

Java 文件 android.content.Context.bindService(android.content.Intent, android.content.ServiceConnection, android.content.Context.BindServiceFlags)

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於

BindService(Intent, Bind, IExecutor, IServiceConnection)

#bindService(Intent, ServiceConnection, int) bindService(Intent, ServiceConnection, int) 執行器一樣,用來控制 ServiceConnection 回調。

[Android.Runtime.Register("bindService", "(Landroid/content/Intent;ILjava/util/concurrent/Executor;Landroid/content/ServiceConnection;)Z", "GetBindService_Landroid_content_Intent_ILjava_util_concurrent_Executor_Landroid_content_ServiceConnection_Handler", ApiSince=29)]
public virtual bool BindService(Android.Content.Intent service, Android.Content.Bind flags, Java.Util.Concurrent.IExecutor executor, Android.Content.IServiceConnection conn);
[<Android.Runtime.Register("bindService", "(Landroid/content/Intent;ILjava/util/concurrent/Executor;Landroid/content/ServiceConnection;)Z", "GetBindService_Landroid_content_Intent_ILjava_util_concurrent_Executor_Landroid_content_ServiceConnection_Handler", ApiSince=29)>]
abstract member BindService : Android.Content.Intent * Android.Content.Bind * Java.Util.Concurrent.IExecutor * Android.Content.IServiceConnection -> bool
override this.BindService : Android.Content.Intent * Android.Content.Bind * Java.Util.Concurrent.IExecutor * Android.Content.IServiceConnection -> bool

參數

service
Intent

此值不可能是空值。

flags
Bind

值為 0 或以下組合:BIND_AUTO_CREATE BIND_DEBUG_UNBIND BIND_NOT_FOREGROUND BIND_ABOVE_CLIENT BIND_ALLOW_OOM_MANAGEMENT BIND_WAIVE_PRIORITY BIND_IMPORTANT BIND_ADJUST_WITH_ACTIVITY BIND_NOT_PERCEPTIBLE BIND_ALLOW_ACTIVITY_STARTS BIND_INCLUDE_CAPABILITIES BIND_SHARED_ISOLATED_PROCESS BIND_PACKAGE_ISOLATED_PROCESS BIND_EXTERNAL_SERVICE

executor
IExecutor

ServiceConnection 上的回調會在執行器上呼叫。 必須使用同一個實例來執行同一個 ServiceConnection 實例。

conn
IServiceConnection

此值不可能是空值。

傳回

如 所述 #bindService(Intent, ServiceConnection, int) bindService(Intent, ServiceConnection, int)的結合結果。

屬性

備註

#bindService(Intent, ServiceConnection, int) bindService(Intent, ServiceConnection, int) 執行器一樣,用來控制 ServiceConnection 回調。

此方法僅接受 32 位元旗標,若要傳入 64 位元旗標,則改為呼叫 #bindService(Intent, BindServiceFlags, Executor, ServiceConnection)

Java 文件 android.content.Context.bindService(android.content.Intent, int, java.util.concurrent.Executor, android.content.ServiceConnection)

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於

BindService(Intent, Context+BindServiceFlags, IExecutor, IServiceConnection)

請參見 bindService(Intent, int, Executor, ServiceConnection) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

[Android.Runtime.Register("bindService", "(Landroid/content/Intent;Landroid/content/Context$BindServiceFlags;Ljava/util/concurrent/Executor;Landroid/content/ServiceConnection;)Z", "GetBindService_Landroid_content_Intent_Landroid_content_Context_BindServiceFlags_Ljava_util_concurrent_Executor_Landroid_content_ServiceConnection_Handler", ApiSince=34)]
public virtual bool BindService(Android.Content.Intent service, Android.Content.Context.BindServiceFlags flags, Java.Util.Concurrent.IExecutor executor, Android.Content.IServiceConnection conn);
[<Android.Runtime.Register("bindService", "(Landroid/content/Intent;Landroid/content/Context$BindServiceFlags;Ljava/util/concurrent/Executor;Landroid/content/ServiceConnection;)Z", "GetBindService_Landroid_content_Intent_Landroid_content_Context_BindServiceFlags_Ljava_util_concurrent_Executor_Landroid_content_ServiceConnection_Handler", ApiSince=34)>]
abstract member BindService : Android.Content.Intent * Android.Content.Context.BindServiceFlags * Java.Util.Concurrent.IExecutor * Android.Content.IServiceConnection -> bool
override this.BindService : Android.Content.Intent * Android.Content.Context.BindServiceFlags * Java.Util.Concurrent.IExecutor * Android.Content.IServiceConnection -> bool

參數

service
Intent

此值不可能是空值。

flags
Context.BindServiceFlags

此值不可能是空值。

executor
IExecutor

此值不可能是空值。 回調與監聽事件透過此執行器派遣,提供簡單控制使用執行緒的方式。 若要透過應用程式的主執行緒派遣事件,可以使用 Context.getMainExecutor() 。 否則,提供一個執行者,將執行者派遣到適當的執行緒。

conn
IServiceConnection

此值不可能是空值。

傳回

請參見 bindService(Intent, int, Executor, ServiceConnection) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

屬性

備註

請參見 bindService(Intent, int, Executor, ServiceConnection) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

Java 文件 android.content.Context.bindService(android.content.Intent, android.content.Context.BindServiceFlags, java.util.concurrent.Executor, android.content.ServiceConnection)

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於