with updated SDK version now Service class has override method
int onStartCommand (Intent intent, int flags, int startId)
& it has replaced following which was introduce with Android 2.0 (API level 5).
void onStart(Intent intent, int startid)
My question is:
- what is use of params like flag & startId passing as an argument?
- how we can manipulate these params ?
Update 1. 2: Clear :)
Following snapcode clear use case of flags param. Default it received as 0, in case if your service started back then it will be received with flag what we return from onStartCommand(..) method.
void readFlags(int flags) {
switch (flags) {
case START_FLAG_REDELIVERY:
case START_FLAG_RETRY:
// restarted by system, might be kill app form stack.
break;
default:
// on regular startService call from client.
}
}
and startID is pretty much clear, whenever you call stopSelf you should call with this startID, so in case if service has running request by multiple client then it will not kill service, it will simply stop work for this startID. it's generated by system no need to manipulate :).
3. But how to manage this startID to call in stopSelf is still an question ? Any one !!