2017-01-04 5 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 
} 
関連する問題