Splash screen Android Kotlin

 Creat a Activity name  "SplashActivity"


Write code in kotlin file

// Delay for 3 seconds and then launch MainActivity
Handler(Looper.getMainLooper()).postDelayed({
val mainIntent = Intent(this, MainActivity::class.java)
startActivity(mainIntent)
finish()
}, 3000)

Here -  3000 milliseconds = 3 seconds






Got to Manifest file

Add this code for Splash as launcher activity. And remove this code from MainActivity.

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


Full Code:
<activity
android:name=".SplashActivity"
android:exported="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</
activity>







I add lottie animaton on splash xml file.






Another Blog:

How to add lottie Animation:

https://sharwar.blogspot.com/2024/05/add-lottie-animation-to-android-kotlin.html



Comments