Reputation: 567
If I call context.startForegroundService(startServiceIntent) multiple time, will I call onCreate() with a new service intent multiple times or I will I call the first time onCreate for a new service intent and then call onStartCommand()/onHandleIntent() multiple times?
Upvotes: 3
Views: 1447
Reputation: 1006819
It depends if the service is running or not. startForegroundService()
will trigger a call to onCreate()
if that service is not already running.
So, for example:
startForegroundService()
onCreate()
on itonStartCommand()
on it (which may trigger calls to other things, like onHandleIntent()
of IntentService
)startForegroundService()
againonCreate()
callonStartCommand()
on it (which may trigger calls to other things, like onHandleIntent()
of IntentService
)stopService()
or stopSelf()
(or onHandleIntent()
returns, if you are still using IntentService
)startForegroundService()
again, because you really like that methodonCreate()
on itonStartCommand()
on it (which may trigger calls to other things, like onHandleIntent()
of IntentService
)Upvotes: 11