Reputation: 507
My requirement is simple.
I have a simple app. 2 Buttons. and 1 service. Conditions: Button1 clicked,-> Start the IntentService.Button2 clicked -> Stop the IntentService.
The first part works fine. I can start the IntentService using startService(intent) command. However, I cannot stop the IntentService. i.e., stopService(intent) command isn't working. It is neither throwing an error nor doing anything.
Can anyone please shed some light on this??
I searched and found this question How to stop an IntentService? but it doesn't answer my need.
Upvotes: 1
Views: 948
Reputation: 15155
However, you cannot kill the IntentService
. The service will stop automatically after all of thread queues completed. Though you call MyIntentService.this.stopSelf();
from Activity
, the service will stops, but the thread still running in background process.
Upvotes: 1
Reputation: 507
I figured it out. We cannot stop an IntentService till it completes all the steps in the process.
However, we can place an intermediary check Ex: if(boolean continue == true){then do next}.esle {stopSelf(); } And we can change the value of 'continue'to false and instead of 'StopService' command.
Hope it helps someone who has similar problem like me.. :-)
Upvotes: 1
Reputation: 606
You can't stop an IntentService
manually. An IntentService
will stop itself automatically, when there are no more intents for that service to process.
If you want to stop a service by clicking a button, use a normal Service
.
Upvotes: 1