반응형

 

New Activity 생성하기

 

manifests 들어가기

 

intent-filter를 SplashActivity 사이에 껴넣어준다

(여기서 activity 부분에 true 란에 공백이 있는지 한 번더 확인한다. 공백이 있으면 

the element type "application" must be terminated by the matching end-tag "</application>".

이 오류가 뜬다.)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Splash"
        tools:targetApi="31">
        <activity
            android:name=".SplashActivity"
            android:exported="true">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        </activity>

        <activity
            android:name=".MainActivity"
            android:exported="true"></activity>
    </application>

</manifest>

 

 

Splash Activity layout에 Image View 생성

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SplashActivity">

    <ImageView
        android:src="@drawable/love"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

 

 

Splash Activity에 어플 실행 시 첫 화면 딜레이 시간 설정 (Handler)

package com.example.splash

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler

class SplashActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)

        Handler().postDelayed({
            startActivity(Intent(this, MainActivity::class.java))
            finish() },3000)

    }
}

 

정상실행 완료

 

반응형