How to stop an IntentService?

前端 未结 1 1456
天涯浪人
天涯浪人 2020-12-19 05:55

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(

相关标签:
1条回答
  • 2020-12-19 06:25

    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 讨论(0)
提交回复
热议问题