停止一个IntentService [英] Stopping an IntentService
本文介绍了停止一个IntentService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道是否有停止的IntentService没有它完成其工作线程和停止自己的一种方式?
Does anyone know if there is a way of stopping an IntentService without it finishing its work thread and stopping itself?
简单的问题,但我找不到文档中的答案。有没有阻止它的一个简单的方法?
Simple question, but I couldn't find the answer in the documentation. Is there a simple way of stopping it?
感谢
推荐答案
bevor消息到服务入队onStartCommand被调用。这为转发排队的消息。所以你可以只覆盖onStartCommand,这样的事情:
bevor a message to a service is enqueued onStartCommand is called. which forwards the message for queueing. so you could just override onStartCommand, something like that:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent.getAction().equals("Stop"))
stopSelf();
onStart(intent, startId);
return START_NOT_STICKY;
}
欢呼声
这篇关于停止一个IntentService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文