码迷,mamicode.com
首页 > 其他好文 > 详细

所谓的心跳查询

时间:2015-08-29 18:27:38      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

public class QueryManager {
private static Context context;
private static Intent intent;
private static boolean stopFlag;
private static Runnable runnableQueryService;
private static Handler queryHandler;
queryHandler .postDelayed(runnableQueryService, dylaySeconds*1000);//第一次调用延迟

queryHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
String strJson = msg.getData().getString("data");
processServiceQueryData(strJson);
if(!stopFlag) {
queryHandler.postDelayed(runnableQueryService, 20 * 1000);
}
}
};


QueryNewCountManager.runnableQueryService = new Runnable(){
@Override
public void run() {//调用服务进行一次查询
Intent intent = new Intent(context, QueryService.class);
if(queryHandler == null){
return;
}
QueryService.setHandler(queryHandler);
context.startService(intent);
}
};


QueryNewCountManager.intent = new Intent(context, QueryFireCountService.class);

(handler)queryHandler --> (runnable)runnableQueryService --> (service)QueryService(带上queryHandler,查询完后,sendmessage 给 queryHandler)

queryHandler处理QueryService发来的service。然后重新调用runnableQueryService 。

如此反复进行心跳查询。



所谓的心跳查询

标签:

原文地址:http://www.cnblogs.com/lizia/p/4769364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!