I have a listview contains many songs. Each time a song is clicked, I call an IntentService to download this song by sequence.
But sometimes I want cancel a download (for example: the 5th). It means I need to stop the 5th running IntentService. I attempt to stop it by call stopService() but it doesn't work.
Can anyone tell me a good way to stop IntentService? Thanks so much for your help.
There is only one running IntentService
, per <service>
element in your manifest. If you call startService()
six times, at most one IntentService
will be running. Commands will queue up and be processed one at a time by onHandleIntent()
, if the IntentService
is processing a command when another command is sent.
In your case, since you cannot readily cancel an outstanding command with IntentService
, you will probably need to create your own version of IntentService
, where you create your own Service
subclass with its own work queue, one where you have the ability to cancel commands that are not yet running.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With