Challenge - 5 Problems
Cloud Messaging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Handling Notification Click Behavior
You have a Firebase push notification that should open MainActivity when clicked. Which option correctly sets the
PendingIntent to achieve this behavior?Android Kotlin
val intent = Intent(this, MainActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
Attempts:
2 left
💡 Hint
Use PendingIntent.getActivity for opening an activity on notification click.
✗ Incorrect
Only PendingIntent.getActivity creates an intent to open an activity. Flags FLAG_UPDATE_CURRENT and FLAG_IMMUTABLE ensure the intent updates properly and is secure.
🧠 Conceptual
intermediate1:30remaining
Firebase Cloud Messaging Token Purpose
What is the main purpose of the Firebase Cloud Messaging (FCM) registration token in an Android app?
Attempts:
2 left
💡 Hint
Think about how Firebase knows where to send notifications.
✗ Incorrect
The FCM token is a unique ID for each app installation, allowing Firebase to target push notifications to that specific device.
❓ lifecycle
advanced2:00remaining
Handling Notification in Foreground
When your Android app receives a Firebase push notification while in the foreground, which method should you override to handle the message and show a custom notification?
Android Kotlin
class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
// Your code here
}
}Attempts:
2 left
💡 Hint
FirebaseMessagingService has a method called when messages arrive.
✗ Incorrect
onMessageReceived is called for messages received while app is in foreground, allowing custom handling and notification display.
📝 Syntax
advanced2:30remaining
Correct Kotlin Syntax for Notification Channel Creation
Which Kotlin code snippet correctly creates a notification channel for Android 8.0+ devices?
Attempts:
2 left
💡 Hint
NotificationChannel constructor requires id, name, and importance.
✗ Incorrect
The NotificationChannel constructor needs three parameters: id (String), name (String), and importance (int). Option B uses correct parameters and method calls.
🔧 Debug
expert3:00remaining
Debugging Missing Notifications on Android 13+
Your app targets Android 13 and above. Users report they do not receive push notifications. What is the most likely cause?
Attempts:
2 left
💡 Hint
Android 13 introduced a new permission for notifications.
✗ Incorrect
Starting Android 13, apps must request POST_NOTIFICATIONS permission at runtime to show notifications. Without it, notifications won't appear.