Skip to content

Instantly share code, notes, and snippets.

@wajahatkarim3
Created December 25, 2019 13:05
Show Gist options
  • Save wajahatkarim3/135766079c689107f1b6edcb88568328 to your computer and use it in GitHub Desktop.
Save wajahatkarim3/135766079c689107f1b6edcb88568328 to your computer and use it in GitHub Desktop.
Splash screen with Kotlin Coroutines
package com.wajahatkarim.splashscreen
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.*
class CoroutinesSplashActivity : AppCompatActivity() {
val activityScope = CoroutineScope(Dispatchers.Main)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_coroutines_splash)
activityScope.launch {
delay(3000)
var intent = Intent(this@CoroutinesSplashActivity, HomeActivity::class.java)
startActivity(intent)
finish()
}
}
override fun onPause() {
activityScope.cancel()
super.onPause()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment