2010년 7월 26일 월요일

Android에서 Timer 사용하기

스플래쉬 화면은 잠깐 표시되고
다음 화면으로 넘어가기 때문에
이것을 타이머를 사용해서 구현했다.

private Timer mTimer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);

mTimer = new Timer();
mTimer.schedule(new TimerTask() {
@Override
public void run() {
TimerMethod(); // 지정된 시간에 실행할 메소드
}
}, 5000); // 밀리세컨드 단위로 딜레이될 시간
}

private void TimerMethod(){
Intent intent = new Intent(DhrActivity.this, LoginActivity.class);
startActivity(intent);
mTimer.cancel(); // 타이머를 취소하지 않으면 계속 실행이 된다.
finish(); // finish를 하지 않으면 뒤로가기 버튼을 누를 때 스플래쉬 화면으로 간다.
}

댓글 없음:

댓글 쓰기