How do I restart a service to call oncreate again?

2

Hey guys, I have a service and I have all his logic in OnCreate. The problem is that I need it to go through the oncreate again when I perform an interaction in my activity.

I've tried using

stopService(new Intent(this, YourService.class)); startService(new Intent(this, YourService.class));

But it did not work. Anyone know how I can do this?

    
asked by anonymous 15.11.2016 / 15:38

1 answer

3

The task logic that a Service performs should not be placed in the onCreate () . The responsibility of onCreate() is to initialize the Service, nothing more.

So all this logic should be put into the onStartCommand () , which will be called whenever you run startService(new Intent(this, YourService.class)); .

    
15.11.2016 / 16:16