I am starting a service with a click on a button :
Intent intent = new Intent(getActivity(), UploadService.class);
getActivity().startService(intent);
My apps makes it possible to launch several services.
I know that the first time, onCreate() is called, then if the services is running, onStartCommand() is called.
onStartCommand returns START_STICKY.
But I’m facing a strange behavior :
On the first click, the Service is called, onCreate() then onStartCommand()… etc.
On the second click, while the Service is still running, onStartCommand()… etc.
But when the first is finished, onDestroy() is called, while the second is still in progress… ?
How to avoid that?
Thanks
If you start the Service that is already running then
onDestroy()of Service won’t be called and the instance of Service already running will be brought to front but if your Service is finished/stopped explicitly then only itsonDestroy()will be called.