안규 공부방

Android > Handler - postDelayed (대기후 실행하기)

등록일 : 2017-07-06 17:21 조회수 : 93,595

Handler를 이용하여 딜레이(지연)시키기. .postDelayed

postDelayed  메서드를 이용하면 작업을 잠시 지연시킬 수 있습니다. 어플를 실행시켜 보면 첫화면 이미지가 나온후

1초후에 메인 activity 화면으로 전환되는 예제를 보셨을 겁니다. 이 경우 사용하게 되면 간단히 구현 할 수 있습니다.
 
	Handler mHandler = new Handler();
	mHandler.postDelayed(new Runnable()  {
		public void run() {
			
			//#명령어

			MainActivity.this.finish();		//MainActivity 완료
			
			Intent myIntent = new Intent(getApplicationContext(), main.class);
			startActivity(myIntent);		//main.class 시작
		}
	}, 3000);
	



//3000(3초) 뒤에 #명령어 아래부분을 실행한다.!  

MainActivity.this.finish(); //MainActivity 완료
Intent myIntent = new Intent(getApplicationContext(), main.class);
startActivity(myIntent); //main.class 시작

끝. 간단하지요잉

 
※ 혹시 도움이 되셨다면 댓글에 한마디 남겨주세요!
작성자   비밀번호
자동글 방지     (자동글 방지 기능입니다.)
내용   댓글달기 
이메일 문의 : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.