It just means that you shouldn’t register the callback after onCreate().
So you can do this
private val checkPermission = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
...
}
and then launch the check anytime you need it
checkPermission.launch(array-of-permissions)
The reason:
When starting an activity for a result, it is possible (and, in cases of memory-intensive operations such as camera usage, almost certain) that your process and your activity will be destroyed due to low memory.
For this reason, the Activity Result APIs decouple the result callback from the place in your code where you launch the other activity. As the result callback needs to be available when your process and activity are recreated, the callback must be unconditionally registered every time your activity is created, even if the logic of launching the other activity only happens based on user input or other business logic.