imp

PHOTO EMBED

Fri Apr 15 2022 10:40:22 GMT+0000 (UTC)

Saved by @anasrathore #kotlin

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)
    }
}

content_copyCOPY