Timer simple TimerTask Java Android example

TimerTask with updating of TextView here

 
package cz.okhelp.timer;
 
import java.util.Timer;
import java.util.TimerTask;
 
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
 
public class TimerActivity extends Activity {
TextView hTextView;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        hTextView = (TextView)findViewById(R.id.idTextView);
        MyTimerTask myTask = new MyTimerTask();
        Timer myTimer = new Timer();
//        public void schedule (TimerTask task, long delay, long period) 
//        Schedule a task for repeated fixed-delay execution after a specific delay.
//
//        Parameters
//        task  the task to schedule. 
//        delay  amount of time in milliseconds before first execution. 
//        period  amount of time in milliseconds between subsequent executions. 
 
        myTimer.schedule(myTask, 3000, 1500);        
 
    }
class MyTimerTask extends TimerTask {
	  public void run() {
		  // ERROR
		 hTextView.setText("Impossible");
		 // how update TextView in link below  
                 // http://android.okhelp.cz/timer-task-timertask-run-cancel-android-example/
 
	    System.out.println("");
	  }
	}
 
 
}

http://android.okhelp.cz/asynctask-example-android-with-progressbar/
http://android.okhelp.cz/timer-task-timertask-run-cancel-android-example/

This entry was posted in Android Examples Code and tagged , . Bookmark the permalink.


Comments are closed.

41,815 views