What if you could get data back from another screen without messy code or lost info?
Why Activity results in Android Kotlin? - Purpose & Use Cases
Imagine you have two screens in your app: one to pick a photo and another to show it. You want to send the photo back from the picker screen to the main screen manually.
You try to pass data by saving it somewhere temporary or using complicated global variables.
This manual way is slow and confusing. You might lose data if the app closes or crashes. It's hard to keep track of where the data is and when it arrives. Bugs happen easily, and the code becomes messy.
Activity results let you start a screen and wait for it to send back data cleanly. Android handles the communication for you. You just write simple code to get the result when the other screen finishes.
startActivity(intent) // no easy way to get result back
val launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == RESULT_OK) {
val data = result.data
// use returned data
}
}
launcher.launch(intent)You can easily get data back from another screen, making your app interactive and user-friendly without messy code.
When a user picks a contact from their address book, your app can get the chosen contact's info right away and show it on the main screen.
Manual data passing between screens is error-prone and complicated.
Activity results provide a clean, reliable way to get data back from another screen.
This makes your app easier to build, understand, and maintain.