Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
Last active October 28, 2021 06:43
Show Gist options
  • Save EmmanuelGuther/b0c7830407de6d2c4f598a44d7360e66 to your computer and use it in GitHub Desktop.
Save EmmanuelGuther/b0c7830407de6d2c4f598a44d7360e66 to your computer and use it in GitHub Desktop.
Use of registerForActivityResult Android activity
//There are 4 simple steps to follow while replacing the depricated method startActivityForResult(...).
private val activityResult = this.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
when(result.resultCode){
123 ->{}
6353 ->{}
}
}
private fun navigateToXActivity(activity: AppCompatActivity, itLatLng: LatLng?, address: String) {
activityResult.launch(XActivity.launch(activity,itLatLng,address)) //XActivity.launch(activity,itLatLng,address) return a intent
}
//returning back to source activity, code will remain the same like -
val resultIntent = Intent()
resultIntent.putExtra("NAME OF THE PARAMETER", searchAddressModel);
setResult(123, resultIntent)
finish()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment