語言

ContextWrapper.StartForegroundService(Intent) 方法

定義

類似於 startService(Intent) ,但隱含承諾服務一旦開始執行就會呼叫 startForeground(int, android.app.Notification)。 服務會獲得相當於 ANR 間隔的時間來完成此事,否則系統會自動當機,屆時執行 SDK 版本 Build.VERSION_CODES 的裝置會記錄內部異常 ForegroundServiceDidNotStartInTimeException。S或更晚。 在較舊的 Android 版本中,會記錄一個內部例外 RemoteServiceException,並附有相應訊息。 與一般的 startService(Intent) 不同,此方法可隨時使用,無論服務的應用程式是否處於前景狀態。 注意:從 SDK 版本 Build.VERSION_CODES 開始。S,針對 SDK 版本 Build.VERSION_CODES 的應用程式。S 級以上的用戶不得從背景啟動前景服務。 詳情請參見行為變更:針對 Android 12 的應用程式。

[Android.Runtime.Register("startForegroundService", "(Landroid/content/Intent;)Landroid/content/ComponentName;", "GetStartForegroundService_Landroid_content_Intent_Handler", ApiSince=26)]
public override Android.Content.ComponentName? StartForegroundService(Android.Content.Intent? service);
[<Android.Runtime.Register("startForegroundService", "(Landroid/content/Intent;)Landroid/content/ComponentName;", "GetStartForegroundService_Landroid_content_Intent_Handler", ApiSince=26)>]
override this.StartForegroundService : Android.Content.Intent -> Android.Content.ComponentName

參數

service
Intent

識別即將啟動的服務。 意圖必須完全明確(提供元件名稱)。 意圖附加值可包含,以配合此特定啟動呼叫提供論點。

傳回

此值可能是零值。

屬性

備註

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

Java 文件 android.content.ContextWrapper.startForegroundService(android.content.Intent)

適用於