做使用计时器在Android http请求 [英] doing http request from android using Timer

查看:166
本文介绍了做使用计时器在Android http请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写的Andr​​oid聊天应用程序,我想知道
它是很好的做法做周期性请求到web服务器获取
在开辟新AsynkTask线程采用了android定时器新消息

I want to write android chat application and I want to know is it good practice to do periodical requests to web server for getting new messages using android Timer by opening new AsynkTask thread in

private Runnable Timer_Tick = new Runnable() {
    public void run() {

    //This method runs in the same thread as the UI.               

    //Do something to the UI thread here

    }
};

方法?

感谢。

推荐答案

为什么不,但如果你希望你的聊天应用程序能够发送新邮件通知到用户,而屏幕关闭,那么你会实现定时器它设置到服务器定期请求的服务,通过报警也许更多:

Why not but if you want your chat application to be able to send notifications of new messages to the user while screen is off then you'd implement the timer in a service, maybe more via an alarm that sets periodic requests to the server :


  • 设置闹钟(不精确重复)发送意图广播接收机。

  • 广播接收器启动的服务。

  • 服务启动一个的AsyncTask请求的Web服务器。

  • 服务发送(或不),如果有任何新的消息的用户通知。

  • 服务停止本身。

这篇关于做使用计时器在Android http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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