Monday, 28 May 2012

How to use Timer in Android for update UI

public class myActivity extends Activity {
 private Timer myTimer;
 /** Called when the activity is first created. */
 public void onCreate(Bundle icicle) {

  myTimer = new Timer();
  myTimer.schedule(new TimerTask() {
   public void run() {

  }, 0, 1000);
 private void TimerMethod()
  //This method is called directly by the timer
  //and runs in the same thread as the timer.
  //We call the method that will work with the UI
  //through the runOnUiThread method.
 private Runnable Timer_Tick = new Runnable() {
  public void run() {
  //This method runs in the same thread as the UI.            
  //Do something to the UI thread here

No comments:

Post a Comment