In an Android application, how do you start a new activity (GUI) when a button in another activity is clicked, and how do you pass data between these two activities?
First Activity
startActivity(Intent(this, SecondActivity::class.java)
.putExtra("key", "value"))
Second Activity
val value = getIntent().getStringExtra("key")
Suggestion
Always put keys in constant file for more managed way.
companion object {
val PUT_EXTRA_USER = "user"
}
startActivity(Intent(this, SecondActivity::class.java)
.putExtra(PUT_EXTRA_USER, "value"))