January 31, 2022

Splash Screen in Kotlin

          On this blog I am going to explain how to show a splash screen using Handler. You can find more about Handler from Here.  On this I am going to show the redirection to new Activity page after the delay I set.  Redirection will be from SplashActivity which is my splash screen to MainActivity which is my landing page

Here I am using a delay of 4000 MS (4 Seconds)


Here I am using  postDelayed function for this,

fun postDelayed(r: Runnable!, delayMillis: Long): Boolean


Sample Code


import android.content.Intent
import android.os.Bundle
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import com.example.MainActivity
class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)

Handler().postDelayed({

val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
        }, 4000)

}
}

2 comments:

  1. Iron Stickers | - TITNIA.NET
    A unique Iron columbia titanium Sticker. The iconic trademark titanium blue ps4 controller is produced for a titanium core and for decorative 2014 ford fusion energi titanium purposes. Iron titanium piercings Stickers are made in a unique hypoallergenic titanium earrings

    ReplyDelete
  2. We’ll rabbit toys begin with a basic definition of CNC and then move on to flesh out what it's, how it it} works, and how and where to obtain CNC training. Based in Los Angeles, Billy Max has been an assistant professor of mechanical engineering with a state college, and has been writing engineering and business and finance-related articles since 2005. His articles have appeared in IEEE Transactions and Business Solutions web sites.

    ReplyDelete