Service.OnTimeout Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
| OnTimeout(Int32, ForegroundService) |
Callback called when a particular foreground service type has timed out. |
| OnTimeout(Int32) |
Callback called on timeout for ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE. |
OnTimeout(Int32, ForegroundService)
Callback called when a particular foreground service type has timed out.
[Android.Runtime.Register("onTimeout", "(II)V", "GetOnTimeout_IIHandler", ApiSince=35)]
public virtual void OnTimeout(int startId, Android.Content.PM.ForegroundService fgsType);
[<Android.Runtime.Register("onTimeout", "(II)V", "GetOnTimeout_IIHandler", ApiSince=35)>]
abstract member OnTimeout : int * Android.Content.PM.ForegroundService -> unit
override this.OnTimeout : int * Android.Content.PM.ForegroundService -> unit
Parameters
- startId
- Int32
int: the startId passed to onStartCommand(Intent,int,int) when the service started.
- fgsType
- ForegroundService
int: the ERROR(foreground service type/android.content.pm.ServiceInfo.ForegroundServiceType foreground service type) which caused the timeout. Value is either 0 or a combination of the following: ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST ServiceInfo.FOREGROUND_SERVICE_TYPE_NONE ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE ServiceInfo.FOREGROUND_SERVICE_TYPE_HEALTH ServiceInfo.FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING ServiceInfo.FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROCESSING ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
- Attributes
Remarks
Callback called when a particular foreground service type has timed out. This callback is meant to give the app a small grace period of a few seconds to finish the foreground service of the associated type - if it fails to do so, the app will crash. The foreground service of the associated type can be stopped within the time limit by stopSelf(), Context.stopService(android.content.Intent) or their overloads. stopForeground(int) can be used as well, which demotes the service to a "background" service, which will soon be stopped by the system. The specific time limit for each type (if one exists) is mentioned in the documentation for that foreground service type. See dataSync for example. Note: time limits are restricted to a rolling 24-hour window - for example, if a foreground service type has a time limit of 6 hours, that time counter begins as soon as the foreground service starts. This time limit will only be reset once every 24 hours or if the app comes into the foreground state.
Android reference for android.app.Service.onTimeout.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
OnTimeout(Int32)
Callback called on timeout for ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE.
[Android.Runtime.Register("onTimeout", "(I)V", "GetOnTimeout_IHandler", ApiSince=34)]
public virtual void OnTimeout(int startId);
[<Android.Runtime.Register("onTimeout", "(I)V", "GetOnTimeout_IHandler", ApiSince=34)>]
abstract member OnTimeout : int -> unit
override this.OnTimeout : int -> unit
Parameters
- startId
- Int32
int: the startId passed to onStartCommand(Intent,int,int) when the service started.
- Attributes
Remarks
Callback called on timeout for ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE. See ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE for more details. If the foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE doesn't finish even after it's timed out, the app will be declared an ANR after a short grace period of several seconds. Starting from Android version Build.VERSION_CODES.VANILLA_ICE_CREAM, onTimeout(int, int) will also be called when a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE times out. Developers do not need to implement both of the callbacks on Build.VERSION_CODES.VANILLA_ICE_CREAM and onwards. Note, even though ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE was added on Android version Build.VERSION_CODES.UPSIDE_DOWN_CAKE, it can be also used on on prior android versions (just like other new foreground service types can be used). However, because onTimeout(int) did not exist on prior versions, it will never called on such versions. Because of this, developers must make sure to stop the foreground service even if onTimeout(int) is not called on such versions.
Android reference for android.app.Service.onTimeout.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.