我使用IntentService处理我的应用中的大文件下载。但是当我想取消下载时,我打电话给stopService(intent)
。但onDestroy()
方法已被调用,但下载不会停止。 我还有什么要取消下载? 谢谢。如何停止IntentService?
7
A
回答
8
我还没有想通了这一点,不过我发送一个Intent
有:
intent.putExtra("pause", "yes");
startService(intent);
然后我重写public int onStartCommand(Intent intent, int a, int b)
的IntentService
内(不推荐),而当看到“暂停”是“是”我设置了一个静态布尔型mPaused
至true
。如果在onHandleIntent
中有循环,则在循环条件中添加&& !mPaused
。
当然,这是所有'不好'的代码和黑客...但我希望别人用这样做的正确方式。
+0
不错,我想。这是暂停服务的正确方法。 – 2016-11-16 03:51:27
相关问题
- 1. 如何停止IntentService
- 2. 停止IntentService
- 3. IntentService立即停止
- 4. 如何在运行SensorListener时停止IntentService
- 5. 如何在android中停止intentservice?
- 6. Android停止指定IntentService
- 7. 从活动中停止IntentService
- 8. 停止IntentService只能有效
- 9. 如何停止一个IntentService同时有很多IntentService正在运行
- 10. 当IntentService停止时处理或收听
- 11. 停止IntentService的正确方法
- 12. AlarmManager和IntentService最终停止工作
- 13. 来自IntentService的停止活动
- 14. 如何停止Android系统从重新传递旧意向IntentService?
- 15. 当IntentService暂停
- 16. 如何创建永无止境的IntentService?
- 17. 如何从IntentService
- 18. 当没有断点时,无限IntentService停止工作
- 19. 停止/清除互联网关闭时的IntentService队列?
- 20. 的Android停止IntentService不接近传感器
- 21. Android IntentService调用不会自行停止的烤面包
- 22. 如何停止线程当Tomcat停止
- 23. intentService不会被System终止?
- 24. IntentService防止活动破坏
- 25. Android FusedLocationApi.requestLocation在后台更新:停止应用程序终止时的IntentService
- 26. 如何停止Minitest?
- 27. 如何停止touchesMoved
- 28. 如何停止.click()?
- 29. 如何停止nsurlconnection?
- 30. 如何停止HttpURLConnection.getInputStream()?
您必须使用单例实例并查找处理程序消息以停止下载。 – papachan 2011-03-31 16:51:08
你能给我多一点吗?我真的不知道我应该怎么做。 – notme 2011-04-01 09:19:41