每5秒将请求发送到Web服务 [英] Send request to web service every 5 second
本文介绍了每5秒将请求发送到Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想听sql server数据库以了解android中是否有数据更改,因此我想每5秒向Web服务发送一次请求以了解新数据值.我该怎么做?你能举个例子吗?
I want to listen sql server database for know whether there are changes of data in android so I want to send request to web service every 5 second to know of new data value.How can I do this? Can you give a example about it?
推荐答案
您可以使用AsyncTask完成
You can do it with AsyncTask,
public void callAsynchronousTask() {
final Handler handler = new Handler();
Timer timer = new Timer();
TimerTask doAsynchronousTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
try {
PerformBackgroundTask performBackgroundTask = new PerformBackgroundTask();
// PerformBackgroundTask this class is the class that extends AsynchTask
performBackgroundTask.execute();
} catch (Exception e) {
// TODO Auto-generated catch block
}
}
});
}
};
timer.schedule(doAsynchronousTask, 0, 50000); //execute in every 50000 ms
}
这篇关于每5秒将请求发送到Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文