0
0
Android Kotlinmobile~20 mins

Permission request flow in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Permission Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
1: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?
AThe system shows the permission dialog again to the user.
BThe app crashes because permission is denied permanently.
CThe app receives a callback indicating permission denied without showing the dialog.
DThe app automatically gets the permission without user interaction.
Attempts:
2 left
💡 Hint
Think about how Android handles permissions after the user disables future prompts.
lifecycle
intermediate
1: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?
AonPause()
BonStart()
ConCreate()
DonResume()
Attempts:
2 left
💡 Hint
Consider when the Activity is fully visible and interactive.
📝 Syntax
advanced
2: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 here
ArequestPermissionLauncher.launch("android.permission.CAMERA")
BrequestPermissionLauncher.launch(Manifest.permission.CAMERA)
CrequestPermissionLauncher.launch(Permission.CAMERA)
DrequestPermissionLauncher.launch(Manifest.permission.CAMERA.toString())
Attempts:
2 left
💡 Hint
Use the constant from Manifest.permission for permissions.
🔧 Debug
advanced
2: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()
ArequestPermissionLauncher must be a class-level variable, not local.
BThe callback only triggers if permission is already granted.
CregisterForActivityResult must be called before onCreate.
DThe permission string ACCESS_FINE_LOCATION is incorrect.
Attempts:
2 left
💡 Hint
Consider the lifecycle of the launcher variable.
🧠 Conceptual
expert
2: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?
ARequest both permissions at once using ActivityResultContracts.RequestMultiplePermissions(), then check which are denied and show rationale dialog before re-requesting only denied ones.
BRequest CAMERA permission first, then LOCATION separately without rationale dialogs.
CRequest permissions in manifest only, no runtime requests needed.
DRequest permissions one by one without checking rationale, assuming user will grant eventually.
Attempts:
2 left
💡 Hint
Think about user experience and Android guidelines for multiple permissions.