Introduction
Firebase helps you build Android apps faster by giving you ready tools for common tasks like saving data, user login, and notifications.
Firebase helps you build Android apps faster by giving you ready tools for common tasks like saving data, user login, and notifications.
implementation 'com.google.firebase:firebase-analytics-ktx:21.2.0' implementation 'com.google.firebase:firebase-auth-ktx:21.1.0' implementation 'com.google.firebase:firebase-firestore-ktx:24.4.3'
FirebaseAuth.getInstance().signInWithEmailAndPassword(email, password)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
// User signed in
} else {
// Sign in failed
}
}val db = FirebaseFirestore.getInstance() db.collection("users").document("user1") .set(mapOf("name" to "Anna", "age" to 25))
This simple app tries to sign in a user with Firebase Authentication when it starts. It shows a message if sign-in works or fails.
import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.google.firebase.auth.FirebaseAuth import android.widget.Toast class MainActivity : AppCompatActivity() { private lateinit var auth: FirebaseAuth override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) auth = FirebaseAuth.getInstance() auth.signInWithEmailAndPassword("test@example.com", "password123") .addOnCompleteListener(this) { task -> if (task.isSuccessful) { Toast.makeText(this, "Signed in successfully", Toast.LENGTH_SHORT).show() } else { Toast.makeText(this, "Sign in failed", Toast.LENGTH_SHORT).show() } } } }
Firebase saves you time by handling backend tasks for you.
It works well for small to medium apps and prototypes.
Always secure your Firebase rules to protect user data.
Firebase offers ready-made tools that speed up Android app development.
You can add login, database, and notifications without building servers.
It helps you focus on your app's unique features instead of backend setup.
FirebaseApp.initializeApp(this) val auth = FirebaseAuth.getInstance() println(auth.currentUser == null)
val database = FirebaseDatabase.getInstance()
val ref = database.getReference("users")
ref.setValue("John Doe")Pass the test and this pattern moves unknown