【发布时间】:2016-10-05 23:10:18
【问题描述】:
我想每 5 秒运行一次异步任务,直到 5 分钟,我该怎么做? 我能够每 5 秒运行一次异步任务,但不能限制 5 分钟
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 {
new CheckTxnStatusSTResult().execute(final_verification_card);
Log.d("dinesh","execute in every five seconds"+ final_verification_card);
} catch (Exception e) {
}
}
});
}
};
timer.schedule(doAsynchronousTask, 0, 15000);
}
【问题讨论】:
-
该任务将每 15 秒运行一次,顺便说一句
-
哦,对不起!但我需要运行到 5 分钟
-
如果我可以问,你为什么使用 handler.post?
标签: android multithreading android-asynctask