如何保持一个Intent服务运行 [英] how to keep an Intent service running

查看:176
本文介绍了如何保持一个Intent服务运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

予有Intentservice的两个例子。一个是在commonsware书下载的例子。另一种是在http://www.vogella.com/articles/AndroidServices/article.html#servicecommunication_handler. 这两个例子表明执行有限任务服务,他们都显然是由运行于onHandleIntent活动范围的最后毁了自己。

我写的服务必须有活动,听的东西。一个是LocationListener的监听用于GPS的移动。另一个让文章以REST服务并监听回信。我希望它运行直到时间结束,或直至它被告知启动它的活性退出。

我如何保持它运行?其中,例如,我把我的执行LocationListener的吗? 谢谢,加里

解决方案
  

我如何保持它运行?

您不知道。 IntentService 的目的是做一个作品(或者是几折队列中,如果命令发生迅速进来),然后关机。

  

我写的服务必须有活动,听的东西。

那么你不应该使用 IntentService 。使用普通的服务,用自己的后台线程(S)作为必要的。

I have two examples of Intentservice. One is the Download example in the commonsware book. the other is at http://www.vogella.com/articles/AndroidServices/article.html#servicecommunication_handler. Both of these examples show the service executing a finite task and they both apparently destroy themselves by running to the end of the scope of the onHandleIntent event.

The service I am writing has to have events and listen for things. One is a LocationListener listening for GPS movement. Another makes Posts to a REST service and listens for replys. I want it to run until a time has elapsed or until it was told to quit by the activity that started it.

How do I keep it running? Where, for instance, do I put my implementation of LocationListener? Thanks, Gary

解决方案

How do I keep it running?

You don't. IntentService is designed to do a piece of work (or perhaps a few off a queue, if commands happen to come in rapidly), then shut down.

The service I am writing has to have events and listen for things.

Then you should not be using an IntentService. Use a regular Service, with your own background thread(s) as needed.

这篇关于如何保持一个Intent服务运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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