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
OnTimeout(Int32, ForegroundService) |
Callback called when a particular foreground service type has timed out. |
OnTimeout(Int32) |
Callback called on timeout for |
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
the startId passed to #onStartCommand(Intent, int, int)
when
the service started.
- fgsType
- ForegroundService
the ServiceInfo.ForegroundServiceType foreground service type
which
caused the timeout.
- 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 android.app.Service#stopSelf()
, android.content.Context#stopService(android.content.Intent)
or their overloads. android.app.Service#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 ServiceInfo#FOREGROUND_SERVICE_TYPE_DATA_SYNC 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.
Java documentation for android.app.Service.onTimeout(int, int)
.
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
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 android.os.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 android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM
and onwards.
Note, even though ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE
was added on Android version android.os.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 android.app.Service#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 android.app.Service#onTimeout(int)
is not called on such versions.
Java documentation for android.app.Service.onTimeout(int)
.
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.