App 구동시 시작화면을 나오게 하자

MainActivity 이외의 Activity를 새로 만든다.(여기서는 가칭 IndexActivity)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class IndexActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_index);
//핸들러 객체 생성
//핸들러: 일정시간 뒤에 원하는 작업 수행하게 만들 수 있음
Handler handler = new Handler();
handler.postDelayed(new Runnable() { //postDelayed 메서드를 사용하기 위해선 Runnable 객체를 인자로 자정해야함
@Override
public void run() {
goMainActivity();
}
},1500); //여기서 1500의 단위는 ms(밀리 세컨드)
}
public void goMainActivity() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}

IndexActivity에는 띄우고 싶은 초기화면을 레이아웃에 지정한다.

Naver의 시작 화면

AndroidManifest.xml에서 IndexActivity를 MAIN및 LAUNCHER로 지정해준다.

1
2
3
4
5
6
7
8
<activity
android:name=".IndexActivity"
android:theme="@style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
공유하기