What's the difference in calling
stopSelf()
, stopSelf(int)
or stopService(new Intent(this,MyServiceClass.class))
inside onStartCommand()
?
for example if I start the same services twice this way:
...
Intent myIntent1 = new Intent(AndroidAlarmService.this, MyAlarmService.class);
myIntent1.putExtra("test", 1);
Intent myIntent2 = new Intent(AndroidAlarmService.this, MyAlarmService.class);
myIntent2.putExtra("test", 2);
startService(myIntent1);
startService(myIntent2);
...
And implement onStartCommand in this way:
public int onStartCommand(Intent intent, int flags, int startId)
{
Toast.makeText(this, "onStartCommand called "+intent.getIntExtra("test", 0), Toast.LENGTH_LONG).show();
stopService(new Intent(this,MyAlarmService.class));
return START_NOT_STICKY;
}
I get exactly the same behaviour with the three methods,that is onDestroy will only be called after onStartCommand is executed twice.