Android send data from one activity to the next. Kotlin
Sending or passing data from one activity to the next is common in Android. Below is a sample code to send a piece of string data and receive it on the next activity using Kotlin.
Send data to Activity2.kt
Receive data on Activity2.kt
Send data to Activity2.kt
var dataString = "Cabbage"
val intent = Intent(this@MainActivity, Activity2::class.java)
intent.putExtra("FOOD", dataString)
startActivity(intent)
Receive data on Activity2.kt
val dataStringPassed = intent.getStringExtra("FOOD")
Comments
Post a Comment