Subscribed unsubscribe Subscribe Subscribe

Mobile App Dev Diary

Android (Java, Kotlin), iOS (Swift), Xamarin (C#)

Kotlin 1.1 / Screen transition with Intent

Screen transition in Kotlin version 1.1.

When you transite to “NextActivity”, use this.

val intent = Intent(applicationContext, NextActivity::class.java)
startActivity(intent)

Or you may want to define package-level function to instantiate Intent. Simply speaking, “package-level” means outside class definition.

//package-level functiono
fun getNextActivityIntent(context: Context) : Intent {
    return Intent(context, NextActivity::class.java)
}

You can call this function from Activity class.

startActivity(getDetailActivityIntent(applicationContext))
Remove all ads