語言

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 。

Java 文件 android.content.Context.stopService(android.content.Intent)。

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

適用於

另請參閱