7

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.

Philipp Redeker
  • 3,848
  • 4
  • 26
  • 34

1 Answers1

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.

Malcolm
  • 41,014
  • 11
  • 68
  • 91
albnok
  • 521
  • 2
  • 14