0
0
Android Kotlinmobile~20 mins

Firebase Authentication in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase Authentication Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What happens after successful Firebase email/password sign-in?
Consider this Kotlin code snippet for Firebase Authentication in an Android app:
auth.signInWithEmailAndPassword(email, password)
  .addOnCompleteListener { task ->
    if (task.isSuccessful) {
      // What happens here?
    } else {
      // Handle failure
    }
  }

What is the expected behavior inside the if (task.isSuccessful) block?
Android Kotlin
auth.signInWithEmailAndPassword(email, password)
  .addOnCompleteListener { task ->
    if (task.isSuccessful) {
      // Navigate to main screen
    } else {
      // Show error message
    }
  }
AThe app crashes due to missing exception handling.
BThe app logs out the user immediately.
CThe app shows a loading spinner indefinitely without navigation.
DThe app navigates to the main screen and the user is considered signed in.
Attempts:
2 left
💡 Hint
Think about what happens when sign-in succeeds in Firebase Authentication.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in Firebase user creation code
Which option contains a syntax error in this Firebase Authentication Kotlin code snippet for creating a user?
auth.createUserWithEmailAndPassword(email, password)
  .addOnCompleteListener(this) { task ->
    if (task.isSuccessful) {
      // User created
    }
  }
Android Kotlin
auth.createUserWithEmailAndPassword(email, password)
  .addOnCompleteListener(this) { task ->
    if (task.isSuccessful) {
      // User created
    }
  }
Aauth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this) { task -> if task.isSuccessful { /* User created */ } }
Bauth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this) { task -> if (task.isSuccessful) { /* User created */ } }
Cauth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, { task -> if (task.isSuccessful) { /* User created */ } })
Dauth.createUserWithEmailAndPassword(email, password).addOnCompleteListener { task -> if (task.isSuccessful) { /* User created */ } }
Attempts:
2 left
💡 Hint
Check the syntax of the if statement inside the lambda.
lifecycle
advanced
2:00remaining
What happens if you call FirebaseAuth.getInstance() multiple times?
In an Android app using Firebase Authentication, what is the behavior when you call FirebaseAuth.getInstance() multiple times in different parts of your app?
Android Kotlin
val auth1 = FirebaseAuth.getInstance()
val auth2 = FirebaseAuth.getInstance()
AEach call returns a new independent FirebaseAuth instance.
BThe app crashes due to multiple instances.
CEach call returns the same singleton FirebaseAuth instance.
DThe second call returns null if called too soon.
Attempts:
2 left
💡 Hint
Think about how FirebaseAuth manages its instances internally.
🔧 Debug
advanced
2:00remaining
Why does this Firebase sign-in code never call onComplete?
Given this Kotlin code snippet:
auth.signInWithEmailAndPassword(email, password)
  .addOnCompleteListener { task ->
    if (task.isSuccessful) {
      // Success
    } else {
      // Failure
    }
  }

But the addOnCompleteListener callback never runs. What is the most likely cause?
Android Kotlin
auth.signInWithEmailAndPassword(email, password)
  .addOnCompleteListener { task ->
    if (task.isSuccessful) {
      // Success
    } else {
      // Failure
    }
  }
AThe email and password variables are empty strings.
BThe app is missing internet permission in AndroidManifest.xml.
CThe FirebaseAuth instance was never initialized properly.
DThe addOnCompleteListener is called on a background thread.
Attempts:
2 left
💡 Hint
Check app permissions related to network access.
🧠 Conceptual
expert
2:00remaining
What is the effect of calling signOut() on FirebaseAuth instance?
In an Android app using Firebase Authentication, what is the effect of calling FirebaseAuth.getInstance().signOut()?
Android Kotlin
FirebaseAuth.getInstance().signOut()
AIt clears the current user session and triggers auth state listeners to update.
BIt deletes the user account permanently from Firebase.
CIt only clears cached credentials but keeps the user signed in.
DIt logs out the user but does not notify any listeners.
Attempts:
2 left
💡 Hint
Think about what signOut means for user session and app state.