package kyy.tt.test;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;
public class TimerTest extends Activity {
/** Called when the activity is first created. */
private Timer testtimer;
private myTask mtask = null;
private Handler handler;
private Runnable run;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
handler = new Handler();
run = new Runnable(){
@Override
public void run()
{
Log.i("test","run");
Toast.makeText(TimerTest.this, "3초후에 뜹니다.!!!", 0).show();
}
};
testtimer = new Timer();
mtask = new myTask();
testtimer.schedule(mtask,3000, 3000); // 0.1 초의 시간뒤 0.1초 마다 mtask의 run 을 호출함
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
testtimer.cancel(); // 타이머를 멈춤
}
class myTask extends TimerTask
{
@Override
public void run()
{
handler.post(run);
} //Handler 을 이용하여 Runnable 를 실행함 상황에 맞게 사용할것
}
}
본소스에 제작권은 라플에 있습니다.