手动结束IntentService工作线程
我在手动结束 IntentService onHandleIntent 方法时遇到一些麻烦。我正在捕获一个异常,这对于线程其余部分的执行至关重要,并且我想在捕获异常时停止线程。我尝试调用 stopSelf() 或直接调用 onDestroy() ,我确信这可能是非常糟糕的方法,而且它们不起作用。线程调用它们然后继续。
有人对如何做到这一点有什么好主意吗?
I am having some trouble manually ending the IntentService onHandleIntent method. I am catching an exception which is crucial to the execution of the rest of the thread and I want to stop the thread as i catch the exception. I tried calling stopSelf() or directly calling onDestroy() which I'm sure are probably very bad ways of doing it, and they aren't working. The thread calls them and then continues.
Anyone have any good ideas of how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如sonykuba所说,完成onHandleIntent方法会停止Service。所以你可以这样做:
As sonykuba said, finishing the onHandleIntent method stops the Service. So you could do something like this:
IntentService 完成 OnHandleIntent 后自动停止。无需手动执行此操作。
阅读方法说明 onHandleIntent()
IntentService stops automaticlly after finishing OnHandleIntent. There is no need to do it manually.
Read description of method onHandleIntent()