服务与IntentService,哪个更好运行服务从服务器轮询数据库的价值? [英] Service and IntentService, Which is better to run a service that poll database value from the server?

查看:285
本文介绍了服务与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

这篇关于服务与IntentService,哪个更好运行服务从服务器轮询数据库的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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