woniper

[Android] 어플리케이션 로딩화면(Splash) 구현하기 본문

Android

[Android] 어플리케이션 로딩화면(Splash) 구현하기

woniper1 2013. 6. 12. 22:58

이번 포시팅은 앱의 로딩 화면을 몇초 동안 띄우고 그 후에 앱을 사용할 수 있는 것이다.


예를 들면 아래와 같이 국민앱인 카카오톡과 같이 카톡을 처음 실행하면 아래 이미지가 로딩된 후 카톡을 사용할 수 있다.


로딩의 장점이라면 로딩하는 시간동안 앱의 기본 설정을 셋팅 할 수 있고, 홍보(?) 효과도 있는것 같다. 




자 이제 소스를 보자


레이아웃은 다른 activity 레이아웃과 같이 로딩하고 싶은 이미지로된 레이아웃을 하나 만든다.



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class SplashActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.activity_splash);
		Handler hd = new Handler();
		hd.postDelayed(new splashhandler() , 3000); // 3초 후에 hd Handler 실행
	}
	
	private class splashhandler implements Runnable{
		public void run() {
			startActivity(new Intent(getApplication(), MainActivity.class)); // 로딩이 끝난후 이동할 Activity
			SplashActivity.this.finish(); // 로딩페이지 Activity Stack에서 제거
		}
	}

}

별로 어렵지 않은 소스다. 끄읏~
Comments