Bird
Raised Fist0
Firebasecloud~20 mins

FCM setup in Firebase - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
FCM Setup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding FCM Message Types

Firebase Cloud Messaging (FCM) supports different message types. Which of the following best describes a notification message?

AA message that requires the app to be open to receive it and cannot be delivered in the background.
BA message that contains only data payload and requires the app to handle it explicitly in all states.
CA message that is sent only to iOS devices and ignored by Android devices.
DA message that contains only user-visible content and is handled by the system when the app is in the background.
Attempts:
2 left
💡 Hint

Think about which message type the system displays automatically when the app is not active.

❓ Configuration
intermediate
2:00remaining
FCM Server Key Usage

You want to send messages from your server to client apps using FCM. Which key must you use in the HTTP header for authorization?

AThe Server Key from the Cloud Messaging tab in Firebase console.
BThe Firebase Web API Key found in the project settings.
CThe OAuth 2.0 client ID from Google Cloud Console.
DThe Firebase Realtime Database secret key.
Attempts:
2 left
💡 Hint

Look for the key specifically labeled for Cloud Messaging in Firebase console.

❓ Architecture
advanced
2:30remaining
Designing Reliable FCM Message Delivery

You want to ensure your app receives important messages even if the device is offline for some time. Which FCM feature helps achieve this?

AUsing the 'time_to_live' parameter to specify how long FCM should keep the message if the device is offline.
BSetting the message priority to 'normal' to save battery.
CSending messages only when the app is in the foreground.
DUsing only notification messages without data payload.
Attempts:
2 left
💡 Hint

Consider how long messages stay in FCM storage before they expire.

❓ security
advanced
2:30remaining
Securing FCM Tokens

Which practice best protects user privacy and security when handling FCM registration tokens?

AStoring tokens in plain text on the client device for easy access.
BSharing tokens publicly to allow multiple servers to send messages.
CSending tokens securely to your app server and rotating them periodically.
DEmbedding tokens directly in the app source code.
Attempts:
2 left
💡 Hint

Think about how to keep tokens safe and up to date.

❓ service_behavior
expert
3:00remaining
FCM Message Behavior on Different App States

Consider an Android app receiving an FCM message with both notification and data payload. What happens when the app is in the background?

AThe app receives both notification and data payload immediately in the background without user interaction.
BThe notification is displayed automatically, and the data payload is delivered to the app only when the user taps the notification.
CThe notification is ignored, and only the data payload is delivered silently in the background.
DNeither notification nor data payload is delivered until the app is opened.
Attempts:
2 left
💡 Hint

Recall how Android handles combined payloads when the app is not active.

Practice

(1/5)
1. What is the main purpose of Firebase Cloud Messaging (FCM)?
easy
A. To host web applications
B. To store user data securely in the cloud
C. To create user authentication systems
D. To send notifications and messages to users' devices

Solution

  1. Step 1: Understand FCM's role

    FCM is designed to send notifications and messages to devices.
  2. Step 2: Compare with other Firebase features

    Other options describe different Firebase services, not FCM.
  3. Final Answer:

    To send notifications and messages to users' devices -> Option D
  4. Quick Check:

    FCM = Messaging service [OK]
Hint: FCM = Firebase messaging to devices [OK]
Common Mistakes:
  • Confusing FCM with data storage
  • Thinking FCM handles authentication
  • Assuming FCM hosts websites
2. Which Firebase method is used to request permission for notifications in a web app?
easy
A. Notification.requestPermission()
B. firebase.messaging().getToken()
C. firebase.initializeApp()
D. firebase.auth().signIn()

Solution

  1. Step 1: Identify permission request method

    Web notifications require calling Notification.requestPermission() to ask user consent.
  2. Step 2: Differentiate from other Firebase methods

    getToken() retrieves the token after permission; initializeApp() sets up Firebase; signIn() is for authentication.
  3. Final Answer:

    Notification.requestPermission() -> Option A
  4. Quick Check:

    Permission request = Notification.requestPermission() [OK]
Hint: Permission uses browser Notification API, not Firebase method [OK]
Common Mistakes:
  • Using getToken() to request permission
  • Confusing initializeApp() with permission request
  • Thinking signIn() handles notifications
3. Given this code snippet, what will console.log(token) output if permission is granted and token is retrieved successfully?
const messaging = firebase.messaging();
Notification.requestPermission().then(() => {
  return messaging.getToken();
}).then(token => {
  console.log(token);
}).catch(err => {
  console.error('Error:', err);
});
medium
A. undefined
B. A string token representing the device registration
C. An error message
D. null

Solution

  1. Step 1: Analyze permission and token retrieval

    If permission is granted, messaging.getToken() returns a string token.
  2. Step 2: Understand console.log output

    console.log(token) prints the token string, not undefined or null.
  3. Final Answer:

    A string token representing the device registration -> Option B
  4. Quick Check:

    Successful getToken() = string token [OK]
Hint: getToken() returns string token on success [OK]
Common Mistakes:
  • Expecting undefined or null instead of token
  • Assuming error logs on success
  • Confusing token with permission status
4. You wrote this code to get an FCM token but always get an error. What is the likely mistake?
const messaging = firebase.messaging();
const token = messaging.getToken();
console.log(token);
medium
A. Missing permission request before calling getToken()
B. firebase.messaging() is not initialized
C. getToken() returns a promise, not a direct value
D. console.log() cannot print tokens

Solution

  1. Step 1: Verify permission requirement

    The code calls getToken() without first requesting notification permission using Notification.requestPermission().
  2. Step 2: Consequence of missing permission

    Without granted permission, messaging.getToken() rejects the promise with an error, leading to an unhandled promise rejection error.
  3. Final Answer:

    Missing permission request before calling getToken() -> Option A
  4. Quick Check:

    Permission before getToken() [OK]
Hint: Request permission with Notification.requestPermission() before getToken() [OK]
Common Mistakes:
  • Not using .then() or await with getToken()
  • Forgetting to initialize Firebase
  • Thinking console.log() cannot print tokens
5. You want to ensure your app always sends notifications to the correct device even if the FCM token changes. What is the best practice to handle token updates?
hard
A. Generate a new token manually every time the app starts
B. Store the token once and never update it
C. Listen for token refresh events and update your server with the new token
D. Ignore token changes because they rarely happen

Solution

  1. Step 1: Understand token lifecycle

    FCM tokens can change, so apps must detect and handle updates.
  2. Step 2: Use token refresh listener

    Listening for token refresh events lets the app send new tokens to the server to keep messaging accurate.
  3. Final Answer:

    Listen for token refresh events and update your server with the new token -> Option C
  4. Quick Check:

    Handle token refresh = update server [OK]
Hint: Always update server on token refresh events [OK]
Common Mistakes:
  • Storing token once without updates
  • Manually generating tokens incorrectly
  • Ignoring token changes
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard