Challenge - 5 Problems
Permission Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate1:30remaining
What happens when permission is denied permanently?
In Android, if a user denies a permission and selects "Don't ask again", what is the expected behavior when the app requests the same permission again?
Attempts:
2 left
💡 Hint
Think about how Android handles permissions after the user disables future prompts.
✗ Incorrect
When a user denies permission and selects "Don't ask again", the system no longer shows the permission dialog. Instead, the app immediately receives a denial callback.
❓ lifecycle
intermediate1:30remaining
When to request permissions in Activity lifecycle?
Which lifecycle method is the best place to request runtime permissions in an Android Activity to ensure the UI is ready and the user is not interrupted during startup?
Attempts:
2 left
💡 Hint
Consider when the Activity is fully visible and interactive.
✗ Incorrect
Requesting permissions in onResume() ensures the UI is visible and ready, and the user can respond to the permission dialog without interruption.
📝 Syntax
advanced2:00remaining
What is the correct Kotlin code to request a single permission?
Given the following code snippet, which option correctly requests the CAMERA permission using Activity Result API in Kotlin?
Android Kotlin
val requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
if (isGranted) {
// Permission granted
} else {
// Permission denied
}
}
// Request permission hereAttempts:
2 left
💡 Hint
Use the constant from Manifest.permission for permissions.
✗ Incorrect
The correct way is to pass Manifest.permission.CAMERA directly as a string constant to launch().
🔧 Debug
advanced2:00remaining
Why does the permission callback not trigger?
An app uses registerForActivityResult to request location permission but the callback never executes. What is the most likely cause?
Android Kotlin
val requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
// callback code
}
fun requestLocationPermission() {
requestPermissionLauncher.launch(Manifest.permission.ACCESS_FINE_LOCATION)
}
// Called in onCreate
requestLocationPermission()Attempts:
2 left
💡 Hint
Consider the lifecycle of the launcher variable.
✗ Incorrect
If the launcher is declared inside a function or local scope, it may be garbage collected before the callback triggers. It must be a class-level property.
🧠 Conceptual
expert2:30remaining
How to handle multiple permissions with rationale?
You want to request CAMERA and LOCATION permissions together. If the user denies any permission, you want to show a rationale dialog before requesting again. Which approach correctly implements this flow?
Attempts:
2 left
💡 Hint
Think about user experience and Android guidelines for multiple permissions.
✗ Incorrect
RequestMultiplePermissions allows requesting several permissions at once. After the result, you can detect which were denied and show rationale dialogs before re-requesting only those permissions.