正确的方法来阻止IntentService [英] Proper way to stop IntentService
问题描述
我使用IntentService将图像上传到服务器。我的问题是,我不知道如何/何时停止服务。当我打电话stopself()在onHandleIntent(意向。)这是等待的IntentService队列中所有的意图都被删除。但我不希望从活动停止该服务,因为我想完成,即使我的应用程序没有运行上传proccess。 谢谢你在前进
我的问题是,我不知道如何/何时停止服务。
IntentService
自动停止自己,当 onHandleIntent()
结束,如果没有更多的指令被发送给它,而 onHandleIntent()
正在运行。因此,你不要手动停止 IntentService
自己。
当我打电话stopself()在onHandleIntent(意向。)这是等待的IntentService队列中所有的意图都被删除。
这就是为什么你不这样做。
但我不希望从活动停止该服务,因为我想完成,即使我的应用程序没有运行上传proccess。
然后你让 IntentService
自行停止。
I'm using an IntentService to upload images to a server. My problem is that I don't know how/when to stop the service. When I call stopself() in onHandleIntent(Intent ..) all Intents which are waiting in the IntentService queue are removed. But I don't want to stop the service from an activity because I want to complete upload proccess even if my application is not running. Thank you in advance
My problem is that I don't know how/when to stop the service.
IntentService
automatically stops itself when onHandleIntent()
ends, if no more commands had been sent to it while onHandleIntent()
was running. Hence, you do not manually stop an IntentService
yourself.
When I call stopself() in onHandleIntent(Intent ..) all Intents which are waiting in the IntentService queue are removed.
Which is why you do not do that.
But I don't want to stop the service from an activity because I want to complete upload proccess even if my application is not running.
Then you let the IntentService
stop itself.
这篇关于正确的方法来阻止IntentService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!