The image i've selected from gallery disappear after the configuration changes, so i wanted to get the uri of the image so i can pass it to onSaveInstanceState but i don't know how to do so.
val selectImageFromGalleryResult = registerForActivityResult(
ActivityResultContracts.GetContent()) { uri: Uri? ->
uri?.let {
profileImage.setImageURI(uri)
}
}
selectBtn.setOnClickListener {
profileImage.visibility = View.VISIBLE
selectImageFromGalleryResult.launch("image/*")
}
If i create a global variable,
private lateinit var imageUri: Uri
i get error saying it has not been initialized if i get the value from the above function and try to send it to onSaveInstanceState