Unit 1 - Practice Quiz
1 What is Firebase?
2 Which company currently owns and develops Firebase?
3 Which Firebase feature provides a NoSQL cloud database for storing and syncing data in real-time?
4 What is the primary purpose of Firebase Cloud Messaging (FCM)?
5 Which Firebase feature allows you to run backend code without managing your own servers?
6 What is the name of the configuration file that you must download from the Firebase console and add to your Android app?
7 In which Gradle file do you typically add the Firebase Bill of Materials (BOM) dependency?
build.gradle
gradle.properties
settings.gradle
build.gradle
8 What unique identifier for your Android app must you provide when registering it in the Firebase console?
9 What is the main function of Firebase Authentication?
10 Which of the following is a common sign-in provider supported by Firebase Authentication?
11 Which object represents the currently authenticated user in the Firebase Android SDK?
12 What is a major benefit of using the FirebaseUI library?
13
The FirebaseRecyclerAdapter from the FirebaseUI library simplifies binding data from a Firebase database to which Android view?
TextView
RecyclerView
Button
ImageView
14 How is data structured within the Firebase Realtime Database?
15 Which of the following is used to get the root reference of your Firebase Realtime Database in Android?
Firebase.getDatabase()
FirebaseDatabase.getInstance().getReference()
new DatabaseReference("root")
RealtimeDatabase.getRoot()
16 What does CRUD stand for in the context of database management?
17 Which Firebase Realtime Database method is used to write or replace data at a specific path?
updateChildren()
push()
setValue()
getValue()
18 To add a new item to a list of data in Firebase without specifying an ID, which method is typically used to generate a unique key?
push()
add()
setValue()
create()
19 Which class must you extend to create a service that handles incoming push notifications in an Android app?
NotificationService
FirebaseMessagingService
CloudMessageReceiver
AndroidMessagingService
20 What is the unique token that Firebase Cloud Messaging (FCM) assigns to each app instance?
21 A startup is developing a new social media app with a small team. They need to quickly implement user login, data storage, and push notifications without managing server infrastructure. Which classification best describes Firebase in this context?
22 An e-commerce app requires complex queries to filter products by price, category, and brand simultaneously. It also needs to scale globally with strong data consistency. Which Firebase database solution is better suited for this requirement?
23
When building an Android app with different build flavors (e.g., 'dev' and 'prod') that connect to separate Firebase projects, where should the respective google-services.json files be placed?
app/ directory, and the build system will select the correct one.
dev-google-services.json and prod-google-services.json and placed in the app/ directory.
google-services.json can be used per Android module.
google-services.json for the 'dev' flavor in app/src/dev/ and for 'prod' in app/src/prod/.
24 After a user successfully signs in using Firebase Authentication, the client app receives an ID token. What is the primary purpose of this token for validating the user on a custom backend server?
25
What is the recommended approach for an Android Activity to react to a user signing in or out at any point while the app is running?
FirebaseAuth.getInstance().getCurrentUser() in a background thread.
SharedPreferences and check it only when the app launches.
FirebaseAuth.AuthStateListener in onStart() and unregister it in onStop().
BroadcastReceiver to listen for system-wide authentication changes.
26 A developer needs to add sign-in with Google, Email, and Phone Number to their app. Why might they choose to use the Firebase UI Auth library instead of implementing the Firebase Auth SDK for each provider manually?
27 You are building a chat application using the Firebase Realtime Database. To optimize for performance and scalability, what is the recommended way to structure the data for a group chat with many messages?
/chatRooms/{roomId}/users/{userId}/messages/{messageId}.
/chatRooms/{roomId}/messages: [...].
28
You need to configure Firebase Realtime Database security rules for a userProfiles node. The rule should allow any authenticated user to read any profile, but a user should only be able to write to their own profile data. Which of the following rules accomplishes this?
"rules": {
"userProfiles": {
".read": "auth != null",
"$uid": {
".write": "auth.uid == $uid"
}
}
}
}
"rules": {
"userProfiles": {
"$uid": {
".read": "auth != null",
".write": "auth.token.verified == true"
}
}
}
}
"rules": {
"userProfiles": {
".read": "auth.uid == $uid",
".write": "auth.uid == $uid"
}
}
}
"rules": {
"userProfiles": {
".read": "true",
".write": "auth != null"
}
}
}
29
Given a user object at users/user123 with the data { "name": "Alice", "email": "alice@example.com", "level": 5 }, which CRUD operation would you use to change the level to 6 and add a new status field with the value "active", without affecting the name and email?
database.getReference("users/user123").set({ "level": 6, "status": "active" })
database.getReference("users/user123").removeValue() followed by a setValue() call.
database.getReference("users/user123").setValue({ "level": 6, "status": "active" })
database.getReference("users/user123").updateChildren(new HashMap<String, Object>() {{ put("level", 6); put("status", "active"); }})
30
In a multiplayer game, you are using the Realtime Database to store a player's score. Multiple events can increase the score concurrently. Why is using a transaction (runTransaction()) the correct way to update the score?
setValue() does not work with numeric data.
31 When using Firebase Cloud Messaging (FCM) in an Android app, what is the key difference in behavior when a notification payload is received while the app is in the foreground versus in the background?
onMessageReceived() is only ever called if the message contains a data payload, regardless of app state.
onMessageReceived() is triggered.
onMessageReceived() callback is always triggered for you to handle the message.
32 You are building a feature to send a direct message notification to a specific user. After the user logs into your app, you retrieve and store their unique FCM registration token on your server. How do you use this token to send a notification to only that user's device?
token field in the message payload to the user's specific registration token.
33 On a user's profile screen, you need to load their username and bio once when the screen opens. The data is not expected to change while the user is on that screen. Which method for reading data from the Firebase Realtime Database is most efficient for this use case?
addValueEventListener() to get real-time updates.
addChildEventListener() to listen for changes to child nodes.
addListenerForSingleValueEvent() to fetch the data once.
34
You are using the Firebase UI Auth library and want to build a sign-in screen that only offers Google Sign-In and Email/Password authentication. How would you configure the AuthUI.SignInIntentBuilder?
createSignInIntentBuilder().setExcludedProviders(Arrays.asList("phone", "facebook"))
createSignInIntentBuilder().setAvailableProviders(Arrays.asList(new AuthUI.IdpConfig.GoogleBuilder().build(), new AuthUI.IdpConfig.EmailBuilder().build()))
35 Your app has a "theme of the day" feature that changes the app's color scheme daily. You want to be able to change this theme for all users without shipping a new app update. Which Firebase feature is best suited for this purpose?
36 An Android app successfully connects to Firebase, but after adding a new build variant (e.g., 'staging'), the new variant fails to connect. The error is "Default FirebaseApp is not initialized". What is a likely cause of this issue?
apply plugin: 'com.google.gms.google-services' line is missing or misplaced in the app-level build.gradle file.
google-services.json file has not been placed in the new build variant's source set (app/src/staging/).
37 A user first uses an app with an anonymous account. Later, they decide to create a permanent account using their Google profile. What is the correct Firebase Authentication procedure to merge their anonymous session data with the new Google account?
AuthCredential from the Google Sign-In result and use firebaseAuth.getCurrentUser().linkWithCredential(credential).
38
In the Firebase Realtime Database, which of the following method calls on a DatabaseReference pointing to users/user123 is the standard and most explicit way to delete all data at that location?
ref.removeValue()
ref.setValue("")
ref.clear()
ref.delete()
39 Your news app allows users to subscribe to different categories like 'sports' and 'technology'. If a user wants to receive notifications for 'sports' but not 'technology', which Firebase Cloud Messaging methods should the app call?
FirebaseMessaging.getInstance().setTopics(Arrays.asList("sports"))
FirebaseMessaging.getInstance().subscribeToTopic("sports-only")
FirebaseMessaging.getInstance().subscribeToTopic("sports") and FirebaseMessaging.getInstance().unsubscribeFromTopic("technology")
40 What is a key advantage of Firebase's real-time data synchronization for collaborative applications, such as a shared whiteboard or a group document editor?
41
In a Firebase Realtime Database, multiple users are concurrently trying to increment a 'like' counter on a post. Using a simple setValue(currentValue + 1) call leads to a race condition and lost updates. Which of the following is the most robust solution to ensure atomicity for the increment operation?
runTransaction block to read the current value, increment it, and set the new value.
onSuccessListener to re-fetch the value and set it again if it has changed.
.validate.
ServerValue.increment(1) which is a native atomic operation on the server.
42 When a user signs in with Firebase Authentication, the client receives an ID Token. When this token is sent to your backend server for verification, what is the primary purpose of checking the 'aud' (Audience) claim within the JWT payload?
43
Your Android app receives an FCM message with both notification and data payloads while the app is in the background. What is the expected behavior on the device?
onMessageReceived() is not called. The data payload is delivered in the Intent extras of the launcher Activity if the user taps the notification.
FirebaseMessagingService.onMessageReceived() is triggered, and you are responsible for building and displaying the notification.
FirebaseMessagingService.onMessageReceived() is triggered, and the system tray displays the notification automatically.
44
You are designing a security rule for a userProfiles node in Realtime Database. You want to allow a user to write to their own profile (/userProfiles/$uid) but only if the new email field being written matches the email associated with their authentication token. Which rule correctly implements this complex validation?
"rules": {
"userProfiles": {
"$uid": {
".write": "auth.uid === $uid && newData.child('email').val() === auth.token.email"
}
}
}
}
"rules": {
"userProfiles": {
"$uid": {
".write": "auth.uid === $uid",
".validate": "data.child('email').val() === auth.token.email"
}
}
}
}
"rules": {
"userProfiles": {
"$uid": {
".write": "auth.uid === $uid",
".validate": "newData.child('email').val() === auth.token.email"
}
}
}
}
"rules": {
"userProfiles": {
"$uid": {
".write": "auth.uid === $uid",
"email": { ".validate": "newData.val() == auth.token.email" }
}
}
}
}
45
You are building an Android app with 'dev' and 'prod' product flavors, each requiring a different Firebase project. What is the correct way to configure your build.gradle and project structure to handle the different google-services.json files?
build.gradle, use a conditional statement to define a firebase_config build variable for each flavor.
google-services.json files in app/ and rename them to google-services-dev.json and google-services-prod.json.
app/src/dev/ and app/src/prod/ and place the corresponding google-services.json file inside each.
46
You are using FirebaseUI for Authentication. A user attempts to sign up with an email address that is already associated with an account created via a different provider (e.g., Google). What is the specific error code you should check for in the IdpResponse to handle this account collision scenario and prompt the user to link the accounts?
ErrorCodes.EMAIL_MISMATCH_ERROR
ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT
ErrorCodes.DEVELOPER_ERROR
ErrorCodes.PROVIDER_ERROR
47 You are modeling a social media app in Realtime Database. To display a user's feed, you need to retrieve 20 posts and, for each post, the author's username and profile picture. A naive approach is to nest author data inside each post object. What is the primary scalability problem with this nested approach?
48 You need to implement a custom authentication system where your existing backend server validates user credentials. What is the correct and secure flow for your backend to grant a user access to Firebase services?
signInWithCustomToken().
createUser() on every login and returns the new user's credentials to the client.
createCustomToken(uid) method to generate a signed token, which is sent to the client to be used with signInWithCustomToken().
49
Using the Firebase Admin SDK on a server, you send a high-priority FCM message with a ttl (time_to_live) of 3600 seconds to an Android device that is currently turned off. The device is turned back on 2 hours (7200 seconds) later. What happens?
ttl has expired.
delivery_receipt_requested callback is triggered on the server.
50
To optimize queries in Realtime Database, you add an .indexOn rule for a timestamp child key in your security rules. Which of the following queries will NOT be able to leverage this server-side index?
ref.orderByChild("user_id").equalTo("some_user_id")
ref.orderByChild("timestamp").endAt(1672531200)
ref.orderByChild("timestamp").startAt(1672531200)
ref.orderByChild("timestamp").limitToLast(10)
51 You are building an app that requires complex, chained queries (e.g., "find all cities with a population greater than 1 million in countries that are in Europe"). It also needs robust offline capabilities. Which Firebase database product is architecturally better suited for this task and why?
52
A user authenticated with Google Sign-In tries to sign up using the same email address with the Email/Password provider. Your app correctly catches the FirebaseAuthUserCollisionException. What is the required sequence of actions to link the new Email/Password credential to the existing Google account?
firebaseAuth.signInWithCredential(credential) immediately, which will automatically merge the accounts.
AuthCredential from the exception, sign the user in with Google, and then call firebaseUser.linkWithCredential(credential).
53
What is the primary function of the onDisconnect() operation in the Firebase Realtime Database SDK, and what is a key limitation to be aware of?
54
You need to write a security rule that allows a user to read a specific 'group' document only if their auth.uid is present as a key in the members map of that same group document. Which rule structure is the most efficient and correct way to achieve this?
"rules": {
"groups": {
".read": "query.uid == auth.uid"
}
}
}
"rules": {
"groups": {
"$groupId": {
".read": "root.child('users').child(auth.uid).child('groups').hasChild($groupId)"
}
}
}
}
"rules": {
"groups": {
"$groupId": {
".read": "data.child('members').val().contains(auth.uid)"
}
}
}
}
"rules": {
"groups": {
"$groupId": {
".read": "data.child('members').child(auth.uid).exists()"
}
}
}
}
55 After uploading your release APK to the Play Store, Google Play App Signing re-signs your app with a new key. You notice that Firebase features dependent on the SHA-1 fingerprint, like Google Sign-In and Phone Auth, are failing for users downloading from the store. What is the cause and correct solution?
release.keystore SHA-1 to your Firebase project settings.
56
You are implementing infinite scroll pagination in Realtime Database for a list of items sorted by a unique timestamp. Your initial query is ref.orderByChild("timestamp").limitToFirst(10). To fetch the next page, what is the correct and most performant query?
ref.orderByChild("timestamp").limitToFirst(10).startAt(lastItemTimestamp + 1)
ref.orderByChild("timestamp").limitToFirst(11).startAt(lastItemKey) and then remove the first item on the client side.
ref.orderByChild("timestamp").limitToFirst(10).startAt(lastItemTimestamp, lastItemKey)
ref.orderByChild("timestamp").limitToFirst(10).startAfter(lastItemTimestamp)
57 Which statement accurately describes a key architectural difference between Firebase Realtime Database (RTDB) and Cloud Firestore regarding how they charge for usage?
58 A user's Firebase ID token has expired. Your client code attempts to make an authenticated request to a backend resource protected by Firebase security rules. What is the expected behavior of the Firebase SDK?
auth variable in the security rules will be null.
FirebaseAuthInvalidUserException which must be caught to trigger a re-authentication flow.
59 You want to implement a custom theme for the FirebaseUI Auth flow that matches your app's branding, including specific colors for the primary button and a custom logo. What is the correct method for achieving this deep customization?
styles.xml that inherits from one of the FirebaseUI themes (e.g., FirebaseUI.Auth.Theme) and override specific attributes like colorPrimary and colorButtonNormal. Then, set this style in the createSignInIntentBuilder().
Bundle of color resources to the AuthUI.getInstance().createSignInIntentBuilder() method.
60 You need to send a time-critical notification with a custom sound that should bypass the user's Doze mode settings to the greatest extent possible. Which combination of parameters in the server-side FCM payload is most effective for this purpose?
"priority": "high",
"android": {
"priority": "high",
"notification": { "sound": "custom.wav", "channel_id": "my_channel" }
}
}
"priority": "urgent",
"notification": { "sound": "custom.wav" },
"ttl": "0s"
}
"priority": "high",
"data": { "message": "..." },
"android": {
"notification": { "sound": "custom.wav", "default_vibrate_timings": false }
}
}
"content_available": true,
"apns": { "headers": { "apns-priority": "10" } },
"android": { "sound": "custom.wav" }
}