每三秒执行一次AsyncTask

时间:2015-05-01 14:46:09

标签: java android

我构建了一个返回特定值的AsyncTask类。这个值经常变化,因此,我需要多次调用我的AsyncTask类来显示更新的值。

我从AsyncTask获得了另一个类的结果。

     try {
        output = new task().execute(getconversationid).get();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

当AsyncTask的结果更新时,我再次调用我的其他类来更新所有内容。

     private void call() {

     new GetContacts().execute(id);

     }

    ...

    mobilemessages = contacts.length();

    ...

     myNum = Integer.parseInt(output);

     if(myNum != mobilemessages) {
         call();
     }

我的问题是如何设置定时器或处理程序每​​三秒钟更新一次我的班级电话(任务)?

谢谢。

1 个答案:

答案 0 :(得分:0)

使用Thread.sleep(3000); 3000以毫秒为单位。

Try{

Thread.sleep(3000);

}catch(Exception ex){
}