[ktx] onNeverAskAgain not called
SammyOdenhoven opened this issue · comments
Overview
onNeverAskAgain callback is not called when "Don't ask again" is selected.
Expected
onNeverAskAgain callback is called, so I can show the appropriate UI.
Actual
onNeverAskAgain callback is not called.
Environment
- Running ktx-sample on API 29 and API 30, using ktx v1.1.3
Investigation
After debugging it, I can see that onNeverAskAgain: WeakReference<Fun>?
is null in PermissionRequestViewModel.invoke()
.
After reading through the closed issues, I came across #735. Wondering if the weakreference could be the issue? If I downgrade the ktx library to 1.0.4, onNeverAskAgain
is successfully called.
Reproducible steps
screen-20220315-112550.mp4
Agree, I have the same issue WeakReference
is null. It is null for all three arguments:
requiresPermission: WeakReference<Fun>,
onPermissionDenied: WeakReference<Fun>?,
onNeverAskAgain: WeakReference<Fun>?
It can be reproduced on Android < 10. For example, in my case, I have used an Android 7.1.1 build on Emulator.
I can also reproduce it on Android > 10. The references are null and so going back and forth the callbacks are not invoked.
I'm able to reproduce the problem using ktx:1.1.4, I've found a workaround keeping a reference to the onNeverAskAgain lambda from the Fragment that is constructing the permission request using constructPermissionsRequest; see sample code:
class MyFragment : Fragment() {
private val locationPermissionNeverAskAgain : () -> Unit = { /* never ask again code here */ }
private val locationPermissionRequest = constructPermissionsRequest(
/* other settings here */
onNeverAskAgain = locationPermissionNeverAskAgain
) { /* permission granted code here */ }
}
Probably library should declare onNeverAskAgain as a val on PermissionsRequesterImpl.