Last active
October 28, 2021 06:43
-
-
Save EmmanuelGuther/b0c7830407de6d2c4f598a44d7360e66 to your computer and use it in GitHub Desktop.
Use of registerForActivityResult Android activity
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
//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