package com.example.addressbook import android.content.Intent import android.os.Bundle import android.os.Handler import androidx.appcompat.app.AppCompatActivity class SplashScreen : AppCompatActivity() { private lateinit var runnable:Runnable private val handler = Handler() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_splash) runnable = Runnable { val intent = Intent(this,MainActivity::class.java) startActivity(intent) finish() } handler.postDelayed(runnable,10000) } override fun onDestroy() { handler.removeCallbacks(runnable) super.onDestroy() //Toast.makeText(this,"onDestroy called",Toast.LENGTH_SHORT).show() } fun startNextActivity() { startActivity(Intent(applicationContext, MainActivity::class.java)) } fun skipSplashScreen() { if (handler != null) handler.removeCallbacksAndMessages(null) startNextActivity() } override fun onStop() { super.onStop() // clear handler on stop if (handler != null) handler.removeCallbacksAndMessages(null) } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter