Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop intentservice in android?

Tags:

android

Could anyone tell me how to stop intentservice in Android?

If I use stopservice to stop an intentservice, it doesn't work.

I have browsed the website, but nobody has given a clear answer to this question.

like image 678
user1127497 Avatar asked Jan 03 '12 09:01

user1127497


People also ask

Can we stop intent Service?

Work is submitted to the queue by creating an Intent and then passing that Intent to the StartService method. It is not possible to stop or interrupt the OnHandleIntent method IntentService while it is working.

How do I stop a service from another activity?

You can add a shutdown() method into your AIDL interface, which allows an Activity to request a stopSelf() be called. This encapsulates the stopping logic and gives you the opportunity to control the state of your Service when it is stopped, similar to how you would handle a Thread .

Does IntentService run on background thread?

The IntentService class provides a straightforward structure for running an operation on a single background thread. This allows it to handle long-running operations without affecting your user interface's responsiveness.

What is the difference between IntentService and service?

If the task doesn't require any and also not a very long task you can use service. If the Background task is to be performed for a long time we can use the intent service. Service will always run on the main thread.


2 Answers

Try calling stopSelf() from within the service. The documentation says that some processes may take a long time to complete, so your service is most likely waiting for them to stop. You should probably look into that. Once all requests are complete, the service stops itself.

like image 197
Tomislav Markovski Avatar answered Sep 21 '22 13:09

Tomislav Markovski


The IntentService is built to stop itself when the last Intent is handled by onHandleIntent(Intent) - i.e. you do not need to stop it, it stops it self when it's done.

like image 44
Jens Avatar answered Sep 22 '22 13:09

Jens