As the title details, I have a working implementation of a Activity A and B, with Activity A having an ActivityLauncher from Android's ActivityLauncherApi and handling a result with intent data back from Activity B, which has a onItemClick function on its recyclerview list items.
Normal implementation has been done such as Activity A launches an ActivityLauncher via a button click; the ActivityLauncher is defined outside of any and all lifecycle functions in a global variable. This works fine in a normal app flow process, and I have this app locked to portrait so screen rotation configuration change won't occur. However, I have requirements for the app to handle configuration changes for UI resizing due to text size or display size increase in Accessibility settings. This doesn't crash the app and resizes fine, but in Activity B, clicking on the list item does not pass the result back to Activity A.
How can I go about resolving this given my current setup, where Activity A and B have distinct ViewModels that aren't connected or related so I can't leverage that, such that I can still pass a result back to Activity A from B once B's activity has been destroyed and created due to a configuration change?
Activity A (the launching activity)
//global variable outside of lifecycle calls as per documentation example
private val resultActivityHandler = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
when(it.resultCode) {
Activity.RESULT_OK -> { //grab intent data with it.data and process it }
Activity.RESULT_CANCELLED -> { //handle error here }
}
...
//inside onCreate//
binding.button.setOnClickListener {
val intent = Intent(context, ActivityB::class.java)
resultActivityLauncher.launch(intent)
}
Activity B (The activity that does a configuration change when I increase font/display size in Accessibility settings while app is in background and returned to foreground.
//code to set result when list item is clicked
val intent = Intent().apply {
putExtra("key", data)
}
setResult(RESULT_OK, intent)
finish()
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745202333a4616401.html
评论列表(0条)