Easily pass data between Activities in Android

February 07, 2019

Android has this idea of Intents in order to pass specific data between Activities. Intents are typically a little bit tricky to understand but essentially is just a bundle of data that all activities have access to when an activity starts the desired activity. In Kotlin, this is how it looks to pass data using intents:

HomeActivity.kt

val intent = Intent(this@HomeActivity,ProfileActivity::class.java)
intent.putExtra("Username","John Doe")
startActivity(intent)

ProfileActivity.kt

val profileName=intent.getStringExtra("Username")