共用方式為


Context.StopService(Intent) 方法

定義

要求停止指定的應用程式服務。

[Android.Runtime.Register("stopService", "(Landroid/content/Intent;)Z", "GetStopService_Landroid_content_Intent_Handler")]
public abstract bool StopService (Android.Content.Intent? service);
[<Android.Runtime.Register("stopService", "(Landroid/content/Intent;)Z", "GetStopService_Landroid_content_Intent_Handler")>]
abstract member StopService : Android.Content.Intent -> bool

參數

service
Intent

要停止之服務的描述。 意圖必須是完全明確的(提供元件名稱),或指定其目標的特定套件名稱。

傳回

如果有符合已執行之指定意圖的服務,則會停止並 true 傳回;否則 false 會傳回。

屬性

例外狀況

備註

要求停止指定的應用程式服務。 如果服務未執行,則不會發生任何動作。 否則會停止。 請注意,startService() 的呼叫不會計算 -- 這會停止服務,無論啟動多少次。

如果服務在停止時以前景服務的形式執行,則會移除其相關聯的通知。 若要避免這種情況,應用程式可以使用 android.app.Service#stopForeground(int) stopForeground(STOP_FOREGROUND_DETACH) 來將通知與服務的生命週期分離,再停止通知。

請注意,如果已停止的服務仍然具有與 ServiceConnection 集合系結的物件 #BIND_AUTO_CREATE ,則除非移除所有系結,否則不會終結它。 android.app.Service如需服務生命週期的詳細資訊,請參閱檔。

如果您沒有停止指定服務的許可權,此函式將會擲回 SecurityException

android.content.Context.stopService(android.content.Intent)Java 檔。

此頁面的部分是根據 Android 開放原始碼專案所建立和共用的工作進行修改,並根據 Creative Commons 2.5 屬性授權中所述的詞彙使用。

適用於

另請參閱