0
0
Android Kotlinmobile~20 mins

Cloud Messaging (push notifications) in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cloud Messaging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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)
Aval pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE)
Bval pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE)
Cval pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
Dval pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
Attempts:
2 left
💡 Hint
Use PendingIntent.getActivity for opening an activity on notification click.
🧠 Conceptual
intermediate
1:30remaining
Firebase Cloud Messaging Token Purpose
What is the main purpose of the Firebase Cloud Messaging (FCM) registration token in an Android app?
AIt uniquely identifies the app instance to receive push notifications.
BIt stores the user's login credentials securely.
CIt manages the app's local database synchronization.
DIt controls the app's UI theme settings remotely.
Attempts:
2 left
💡 Hint
Think about how Firebase knows where to send notifications.
lifecycle
advanced
2: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
  }
}
AOverride onCreate(savedInstanceState: Bundle?) in Application class.
BOverride onNewIntent(intent: Intent) in MainActivity.
COverride onStartCommand(intent: Intent?, flags: Int, startId: Int) in Service.
DOverride onMessageReceived(remoteMessage: RemoteMessage) in FirebaseMessagingService.
Attempts:
2 left
💡 Hint
FirebaseMessagingService has a method called when messages arrive.
📝 Syntax
advanced
2:30remaining
Correct Kotlin Syntax for Notification Channel Creation
Which Kotlin code snippet correctly creates a notification channel for Android 8.0+ devices?
A
val channel = NotificationChannel("channel_id", "Channel Name", 5)
val manager = getSystemService(NotificationManager::class.java)
manager.createNotificationChannel(channel)
B
val channel = NotificationChannel("channel_id", "Channel Name", NotificationManager.IMPORTANCE_DEFAULT)
val manager = getSystemService(NotificationManager::class.java)
manager.createNotificationChannel(channel)
C
val channel = NotificationChannel("channel_id", NotificationManager.IMPORTANCE_DEFAULT)
val manager = getSystemService(NotificationManager::class.java)
manager.createNotificationChannel(channel)
D
val channel = NotificationChannel("channel_id", "Channel Name")
val manager = getSystemService(NotificationManager::class.java)
manager.createNotificationChannel(channel)
Attempts:
2 left
💡 Hint
NotificationChannel constructor requires id, name, and importance.
🔧 Debug
expert
3: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?
AThe app lacks runtime POST_NOTIFICATIONS permission request.
BNotification channels are not created on Android 13.
CThe Firebase token is expired and needs refreshing.
DThe app is missing INTERNET permission in manifest.
Attempts:
2 left
💡 Hint
Android 13 introduced a new permission for notifications.