Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android service startId parameter

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?

like image 759
Falmarri Avatar asked Aug 30 '10 04:08

Falmarri


1 Answers

What use case would using stopSelf(int) fall under?

Step #1: Call startService()

Step #2: Call startService() again

Step #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 the startService() and stopSelf() calls to match.

like image 63
CommonsWare Avatar answered Sep 26 '22 00:09

CommonsWare