Service behave same like Activity Whatever you want to associate
once with a service will go in onCreate
like initialization
and whenever the service
is called using startService. onStartCommand
will be called. and you can pass any action to perform . like for a music player , You can play ,pause,stop using action
And you do any operation in service
by sending an action and receiving it on onStartCommand
onCreate
work like a Constructor.
Edit in Short
onCreate()
calls only for the first time you start a Service
Whereas onStartCommand()
calls everytime you call the startService
again. It let you set an action like play,stop,pause music.
public void onStartCommand()
{
if(intent.getAction.equals("any.play")
{
//play song
}
else if(intent.getAction.equals("any.stop")
{}
}