我想听sql server数据库知道android中是否有数据更改所以我想每5秒向web服务发送一次请求以了解新的数据值.我该怎么做?你能举个例子吗?
My *_*God 17
你可以用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
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13671 次 |
最近记录: |