Friday, June 2, 2017

Android Splash Screen and start Activity in Kotlin


In this post you will learn how to start new activity using Intent and how to implement splash screen logic in android application using Kotlin.

Code Moved to below link.


http://developine.com
I assume you have two kotlin activities declared in manifest and one of them is launcher activity(your splash screen) and you want to launch MainActivity using Intent in kotlin and you need to stop at SplashActivity for 2–3 Seconds
MainActivity.kt
import android.support.v7.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}
SplashActivity.kt
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.view.WindowManager
import android.view.Window
import android.os.Handler
import android.content.Intent
import android.content.Context

class SplashActivity : AppCompatActivity() {

    internal var SPLASH_TIME_OUT = 2000

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash)
        Handler().postDelayed(
                {
                    startActivity(Intent(this, MainActivity::class.java))
                    finish()
                }, SPLASH_TIME_OUT.toLong())
    }

}

No comments:

Post a Comment

Kotlin Android MVP Dagger 2 Retrofit Tutorial

http://developine.com/building-android-mvp-app-in-kotlin-using-dagger-retrofit/