共用方式為


Service.OnTimeout(Int32) Method

Definition

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.

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.

Applies to