0
0
Android Kotlinmobile~20 mins

Firebase project setup in Android Kotlin - Mini App: Build & Ship

Choose your learning style9 modes available
Build: Firebase Setup Screen
This screen guides the user through the initial Firebase project setup for an Android app using Kotlin. It shows the basic UI to start the setup process and confirms when setup is complete.
Target UI
-------------------------
| Firebase Setup         |
|-----------------------|
|                       |
|  [Start Setup]        |
|                       |
| Status: Not started   |
-------------------------
Add a button labeled 'Start Setup' that triggers Firebase initialization
Show status text below the button that updates to 'Setup Complete' after initialization
Use Kotlin and Android best practices for UI and Firebase setup
Ensure the UI is simple and accessible
Starter Code
Android Kotlin
package com.example.firebaseprojectsetup

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.Button
import android.widget.TextView

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val setupButton: Button = findViewById(R.id.setupButton)
        val statusText: TextView = findViewById(R.id.statusText)

        // TODO: Add Firebase initialization logic here
        setupButton.setOnClickListener {
            // TODO: Update statusText after setup
        }
    }
}
Task 1
Task 2
Solution
Android Kotlin
package com.example.firebaseprojectsetup

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.Button
import android.widget.TextView
import com.google.firebase.FirebaseApp

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val setupButton: Button = findViewById(R.id.setupButton)
        val statusText: TextView = findViewById(R.id.statusText)

        setupButton.setOnClickListener {
            FirebaseApp.initializeApp(this)
            statusText.text = "Setup Complete"
        }
    }
}

We import FirebaseApp from the Firebase library. When the user taps the 'Start Setup' button, we call FirebaseApp.initializeApp(this) to initialize Firebase for the app context. After this, we update the status text to show 'Setup Complete' so the user knows the setup finished successfully.

This simple UI and logic demonstrate the basic Firebase setup step in an Android Kotlin app.

Final Result
Completed Screen
-------------------------
| Firebase Setup         |
|-----------------------|
|                       |
|  [Start Setup]        |
|                       |
| Status: Setup Complete |
-------------------------
User taps the 'Start Setup' button
Firebase initializes in the background
Status text changes from 'Not started' to 'Setup Complete'
Stretch Goal
Add error handling to show a message if Firebase initialization fails
💡 Hint
Use try-catch around FirebaseApp.initializeApp and update statusText with error message on failure