2017-01-04 2 views
0

Если у меня есть что-то вроде example.com/time.php, а выход - всего 20000, так как я могу связать это, чтобы контролировать время обновления, любую идею?контроль времени андроидного обновления в соответствии с выходом веб-страницы

Thread t = new Thread() { 
    @Override 
    public void run() { 
    try { 
     while (!isInterrupted()) { 
     Thread.sleep(10000); // here is the number which should be linked to the webpage output 
     runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
      // update View here! 
      } 
     }); 
     } 
    } catch (InterruptedException e) { 
    } 
    } 
}; 
t.start(); 

ответ

0

Вы должны использовать обработчик для более легкой реализации.

Handler handler = new Handler(); 
Runnable test = new Runnable() { 
    @Override 
    public void run() { 
     //do work 
     handler.post(test, 4000); //wait 4 sec and run again, you can change it programmatically 
    } 
}; 

public void stopTest() { 
    handler.removeCallbacks(test); 
} 

public void startTest() { 
    handler.post(test,0); //wait 0 ms and run 
} 
Смежные вопросы