Android服务startId参数
所以我了解服务生命周期等等。但我很困惑 startId
参数的用途是什么?
public int onStartCommand (Intent intent, int flags, int startId)
我知道它与 stopSelf(int) 结合使用,但我不明白重点是什么或 startId 是在哪里生成的。使用 stopSelf(int) 属于什么用例?
So I understand the service lifecycle and all that. But I'm confused what the startId
parameter is for?
public int onStartCommand (Intent intent, int flags, int startId)
I get that it's used in conjunction with stopSelf(int)
, but I don't see what the point is or where the startId is being generated. What use case would using stopSelf(int) fall under?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
步骤 #1:调用
startService()
步骤 #2:再次调用
startService()
步骤 #3:调用
stopSelf()
此时,我们希望服务不要停止,因为仍有未完成的工作,由第二个
startService()
调用表示。我们希望startService()
和stopSelf()
调用匹配。Step #1: Call
startService()
Step #2: Call
startService()
againStep #3: Call
stopSelf()
At this point, we want the service to not be stopped, since there is still work outstanding, represented by the second
startService()
call. We want thestartService()
andstopSelf()
calls to match.