I use an IntentService to handle large file-downloads in my app. But when i want to cancel the download i call stopService(intent)
. However the onDestroy()
method is been called but the download doesn't stop.
What else do i have to do to cancel the download?
Thanks.
Asked
Active
Viewed 3,297 times
7

Philipp Redeker
- 3,848
- 4
- 26
- 34
-
1you must work with singleton instances and look for a handler message to stop your download. – papachan Mar 31 '11 at 16:51
-
2could you give me a little more? i dont really know what i should do with this. – Philipp Redeker Apr 01 '11 at 09:19
1 Answers
8
I have not figured this out myself, but I send an Intent
with:
intent.putExtra("pause", "yes");
startService(intent);
And then I override public int onStartCommand(Intent intent, int a, int b)
inside the IntentService
(which is not recommended) and seeing that "pause" is "yes" I set a static boolean mPaused
to true
. If you have a loop in onHandleIntent
, add && !mPaused
in the loop condition.
Of course this is all 'bad' code and a hack... but I hope somebody else chimes in with the correct way of doing this.
-
Not a bad code, I think. This is a properly way to pause a service. – Nguyen Minh Binh Nov 16 '16 at 03:51