Service.OnStartCommand(Intent, StartCommandFlags, Int32) 方法

定义

每次客户端通过调用显式启动服务、提供提供的参数以及表示启动请求的唯一整数令牌时,由系统调用 android.content.Context#startService

[Android.Runtime.Register("onStartCommand", "(Landroid/content/Intent;II)I", "GetOnStartCommand_Landroid_content_Intent_IIHandler")]
public virtual Android.App.StartCommandResult OnStartCommand(Android.Content.Intent? intent, Android.App.StartCommandFlags flags, int startId);
[<Android.Runtime.Register("onStartCommand", "(Landroid/content/Intent;II)I", "GetOnStartCommand_Landroid_content_Intent_IIHandler")>]
abstract member OnStartCommand : Android.Content.Intent * Android.App.StartCommandFlags * int -> Android.App.StartCommandResult
override this.OnStartCommand : Android.Content.Intent * Android.App.StartCommandFlags * int -> Android.App.StartCommandResult

参数

intent
Intent

给定提供给 android.content.Context#startService的意向。 如果服务进程消失后正在重启,并且之前已返回除其他 #START_STICKY_COMPATIBILITY任何内容外,则可能为 null。

flags
StartCommandFlags

有关此启动请求的其他数据。

startId
Int32

表示要启动的此特定请求的唯一整数。 与 #stopSelfResult(int) 结合使用。

返回

返回值指示系统应用于服务的当前启动状态的语义。 它可能是与 #START_CONTINUATION_MASK 位关联的常量之一。

属性

注解

每次客户端通过调用显式启动服务、提供提供的参数以及表示启动请求的唯一整数令牌时,由系统调用 android.content.Context#startService。 请勿直接调用此方法。

为了向后兼容,默认实现调用#onStart并返回或#START_STICKY#START_STICKY_COMPATIBILITY返回 。

请注意,系统在服务的主线程上调用此项。 服务的主线程是在同一进程中运行的活动的 UI 操作所在的同一线程。 应始终避免停止主线程的事件循环。 执行长时间运行的操作、网络调用或重磁盘 I/O 时,应启动新线程或使用 android.os.AsyncTask

Java文档android.app.Service.onStartCommand(android.content.Intent, int, int)

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

另请参阅