2017-01-04 7 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 
}