开发者

How to stop an IntentService?

开发者 https://www.devze.com 2023-02-20 21:49 出处:网络
I use an IntentService to handle large file-downloads in my app. But when i want to cancel the download i call stopS开发者_Python百科ervice(intent). However the onDestroy() method is been called but t

I use an IntentService to handle large file-downloads in my app. But when i want to cancel the download i call stopS开发者_Python百科ervice(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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消