-
-
Save Eldhopj/bb055680b39efa54c54e1d911eb09da9 to your computer and use it in GitHub Desktop.
ActivityResult : Suppose ActivityResult & B are activities the navigation is from A -> B We need the result back, A <- B
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// calling the Activity B | |
resultLauncher.launch(Intent(requireContext(), B::class.java)) | |
// we get data in here from B | |
private var resultLauncher = | |
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> | |
when (result.resultCode) { | |
Activity.RESULT_OK -> { | |
result.data?.getStringExtra("VALUE")?.let { | |
// data received here | |
} | |
} | |
Activity.RESULT_CANCELED -> { | |
// cancel or failure | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sending result value back to A | |
if (success) { | |
setResult(RESULT_OK, Intent().putExtra("VALUE", value)) | |
} else { | |
setResult(RESULT_CANCELED) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment