Sobes.tech
Junior — Middle

How can information be transferred between two screens in an Android application?

sobes.tech AI

Answer from AI

In Android, to pass data between two screens (Activities), Intent with extras is usually used.

Example of passing a string from one Activity to another:

// In the first Activity
val intent = Intent(this, SecondActivity::class.java)
intent.putExtra("key", "Hello, second screen!")
startActivity(intent)

// In the second Activity
val message = intent.getStringExtra("key")

You can also use Bundle for passing more complex data or employ ViewModel and LiveData for data exchange between fragments within the same Activity.