手动结束IntentService工作者线程 [英] Manually ending the IntentService worker thread

查看:158
本文介绍了手动结束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?

推荐答案

由于sonykuba说,整理onHandleIntent方法停止服务。所以,你可以做这样的事情:

As sonykuba said, finishing the onHandleIntent method stops the Service. So you could do something like this:

public void onHandleIntent {
  try {
   // ... your code here
  } catch(YourException e) {
    // do something with the exception
    return; // this prevents the rest of the method from execution 
            // and thereby stops the service
  }
  // rest of your code
}

这篇关于手动结束IntentService工作者线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆