服务与IntentService,哪个更好运行服务从服务器轮询数据库的价值?

问题描述:

我曾读过关于服务 IntentService 相当多的资源。来做出决定然而,当,我没有足够的信心来选择,以创建一个后台服务将在一个时间间隔轮询从数据库中的数据,并停止它,当我得到的数据我想既然数据重新使用哪种类型present的请求的状态,例如。订购医学确认状态(等待,已完成,正在进行中)。我需要时一个状态设置为已完成,并发送一个通知以提醒该命令完成用户检测。之后,该服务将自动停止本身。
请您咨询。谢谢你。

I had read quite a number of resources regarding the Service and IntentService. However when come to make a decision, I am not confident enough to choose which type to use in order to create a background service that will poll data from database in a time interval and stop it when I get the data I want since the data represent a status of a request, eg. ordering medicine confirmation status(pending, completed, in progress). I need to detect when a status is set to "completed" and send a notification to alert the user that the order is completed. After that the service will stop itself automatically. Please kindly advice. Thank you.

意图服务 -


  • 工作工作线程,而不是在主线程。

  • Works in Worker Thread , not in Main Thread.

本打算执行它们的作用是独立的线程,然后得到关机。

Intended to execute their action is separate thread and then get shut down.

他们确实履行自己的操作并停止。

They do perform their operation and stops.

理想要亲热之类的东西HTP弄,不要求保持与服务器相连。

Ideal to perfrom things like htp get ,don't require to stay connected with server.

服务 -


  • 运行在主线程。

  • Runs in main thread.

理想时有能够轻松的与服务器相连的要求
(即永久TCP连接),你可以走的路是有使用的AsyncTask或服务承载比较经典的线程执行网络的东西服务(不是故意的)

Ideal when there is requirement to stay connected with server (i.e. permanent tcp connection), the way you can go is to have a service (not an intent one) that performs the networking stuff using an asynctask or a more classic thread hosted in the service