SlideShare a Scribd company logo
Building an Android app with
Jetpack Compose and Firebase
Marina Coelho
Developer Relations Engineer
@coelho_dev
Firebase
Authentication
Firebase and
Compose overview
App architecture
Calling async Firebase
methods
Firestore
Firebase
Authentication
Firebase and
Compose overview
App architecture
Calling async Firebase
methods
Firestore
Drive user engagement
Analytics
Cloud
Messaging
Remote
Config
A/B Testing
Dynamic
Links
In-app
Messaging
Improve app quality
Crashlytics
Performance
Monitoring
Test Lab
App Distribution
Build better apps
Auth
Cloud
Functions
Cloud
Firestore
Hosting
Firebase ML
Realtime
Database
Cloud
Storage
Extensions
Building an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and Firebase
Jetpack Compose
● Android’s modern toolkit for building native UI
● Intuitive and requires less code than writing .xml files
● First stable version of Compose was launched in 2021
Jetpack Compose
@Composable
fun Hello() {
Column(modifier = Modifier.padding(16.dp)) {
var name by remember { mutableStateOf(“”) }
if (name.isNotEmpty()) {
Text(text = "Hello, $name!")
}
}
}
Firebase
Authentication
Firebase and
Compose overview
App architecture
Calling async Firebase
methods
Firestore
Make it So
● Create and edit to-do items
● Add flags
● Add priority
● Add due date
● Mark as complete
Model-View-ViewModel
Model-View-ViewModel + Compose
How it used to be
private lateinit var auth: FirebaseAuth
public override fun onCreate() {
super.onCreate()
auth = Firebase.auth
}
public override fun onStart() {
super.onStart()
val currentUser = auth.currentUser
}
How it is now
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent { FirstComposableFunction() }
}
}
How it is now
class AccountServiceImpl() : AccountService {
override fun getUser(): FirebaseUser? {
return Firebase.auth.currentUser
}
}
Firebase
Authentication
Firebase and
Compose overview
App architecture
Calling async Firebase
methods
Firestore
Synchronous and Asynchronous methods
● Synchronous
○ Returns directly to the caller
○ Blocks the caller thread
● Asynchronous
○ Processing in another thread
○ Return to caller thread once it’s completed
How callback works
fun authenticate(
email: String,
password: String,
onResult: (Throwable?) -> Unit
) {
Firebase.auth.signInWithEmailAndPassword(email,password)
.addOnCompleteListener { onResult(it.exception) }
}
Firebase
Authentication
Firebase and
Compose overview
App architecture
Calling async Firebase
methods
Firestore
Authentication
● Knowing a user's identity allows your app to do many things
○ Securely save user data in the cloud
○ Provide the same personalized experience across all devices
● Firebase Authentication provides backend services, SDKs and UI libraries
● It supports different authentication methods
● Offers Anonymous Authentication
Authentication flow
Enabling it on the console
Enabling it on the console
Enabling it on the console
Adding to code
Add to app/build.gradle file:
dependencies {
implementation 'com.google.firebase:firebase-auth-ktx'
}
Sync Android project with Gradle files again
Providing the ViewModel
@HiltViewModel
class LoginViewModel @Inject constructor() : ViewModel() {
var uiState = mutableStateOf(LoginUiState())
private set
}
The Screen
@Composable
fun LoginScreen(
[...],
viewModel: LoginViewModel = hiltViewModel()
) {
val uiState by viewModel.uiState
}
The UI State
data class LoginUiState(
val email: String = "",
val password: String = ""
)
The Screen
OutlinedTextField(
singleLine = true,
modifier = Modifier.fillMaxWidth(),
value = uiState.email,
onValueChange = { viewModel.onEmailChange(it) },
placeholder = { Text(stringResource(R.String.email)) },
)
The Screen
Button(
onClick = { viewModel.onSignInClick() },
Modifier = Modifier.fillMaxWidth()
) {
Text(text = stringResource(R.String.sign_in))
}
The ViewModel
fun onSignInClick() {
viewModelScope.launch(exceptionHandler) {
accountService.authenticate(email, password) { error ->
if (error == null) {
linkWithEmail()
} else onError(error)
}
}
}
Firebase
Authentication
Firebase and
Compose overview
App architecture
Calling async Firebase
methods
Firestore
Cloud Firestore
● NoSQL document database in the Cloud
● Data is stored into structures called documents
● Retrieve individual or list of documents
● Listen to changes across client apps
● Offers offline support
What a document looks like in Make it So
Mapping data
data class Task(
val id: String = “”,
val title: String = "",
val priority: String = "",
val dueDate: String = "",
val dueTime: String = "",
val description: String = "",
val url: String = "",
val flag: Boolean = false,
val completed: Boolean = false,
val userId: String = ""
)
val task = result.toObject<Task>()
Enabling it on the console
Adding to code
Add to app/build.gradle file:
dependencies {
implementation 'com.google.firebase:firebase-firestore-ktx'
}
Sync Android project with Gradle files again
The service
val query = Firebase.firestore
.collection(TASK_COLLECTION)
.whereEqualTo(USER_ID, userId)
query.addSnapshotListener { value, _ ->
value?.documentChanges?.forEach {
val wasDocumentDeleted = it.type == REMOVED
onDocumentEvent(
wasDocumentDeleted, it.document.toObject<Task>()
)
}
}
The ViewModel
private fun onDocumentEvent(wasDocumentDeleted: Boolean, task: Task) {
if (wasDocumentDeleted) tasks.remove(task)
else updateTaskInList(task)
}
private fun updateTaskInList(task: Task) {
val index = tasks.indexOfFirst { it.id == task.id }
if (index < 0) tasks.add(task) else tasks[index] = task
}
var tasks = mutableStateListOf<Task>()
private set
The Screen
val tasks = viewModel.tasks
LazyColumn {
items(tasks, key = { it.id }) { taskItem ->
TaskItem(
task = taskItem,
onCheckChange = { viewModel.onTaskCheckChange(taskItem) },
onActionClick = { action ->
viewModel.onTaskActionClick(openScreen, taskItem, action)
}
)
}
}
There's a lot more in Firestore!
fun addListener(
userId: String,
onDocumentEvent: (Boolean, Task) -> Unit,
onError: (Throwable) -> Unit
)
fun removeListener()
fun getTask(taskId: String, onError: (Throwable) -> Unit, onSuccess: (Task) -> Unit)
fun saveTask(task: Task, onResult: (Throwable?) -> Unit)
fun deleteTask(taskId: String, onResult: (Throwable?) -> Unit)
fun deleteAllForUser(userId: String, onResult: (Throwable?) -> Unit)
Firebase
Authentication
Firebase and
Compose overview
App architecture
Calling async Firebase
methods
Firestore
Make it So Series
Github @coelho_dev
Blog
Thank you!

More Related Content

PDF
Event driven autoscaling with KEDA
PPTX
Packer
PPTX
Azure Boards.pptx
PPTX
쿠버네티스 ( Kubernetes ) 소개 자료
PDF
Default GitLab CI Pipeline - Auto DevOps
PDF
Event driven workloads on Kubernetes with KEDA
PDF
Essentials of Product Management
PPTX
DevSecOps in the Cloud from the Lens of a Well-Architected Framework.pptx
Event driven autoscaling with KEDA
Packer
Azure Boards.pptx
쿠버네티스 ( Kubernetes ) 소개 자료
Default GitLab CI Pipeline - Auto DevOps
Event driven workloads on Kubernetes with KEDA
Essentials of Product Management
DevSecOps in the Cloud from the Lens of a Well-Architected Framework.pptx

What's hot (20)

PDF
GitHub Actions in action
PDF
Red Hat Openshift on Microsoft Azure
PDF
Cloud-Native CI/CD on Kubernetes with Tekton Pipelines
PDF
Amazon DynamoDB 기반 글로벌 서비스 개발 방법 및 사례::김준형::AWS Summit Seoul 2018
PDF
DevOps Transformation in Technical
PPTX
QGIS 소개 및 ArcMap과의 비교
PDF
CD using ArgoCD(KnolX).pdf
PDF
Serverless and Design Patterns In GCP
PDF
Google Kubernetes Engine (GKE) deep dive
PDF
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCD
PDF
Podman Overview and internals.pdf
PDF
금융사의 AWS기반 Digital Transformation 사례::고종원::AWS Summit Seoul 2018
PDF
Introduction to Github Actions
PDF
stupid-simple-kubernetes-final.pdf
PDF
Gitops Hands On
PDF
Platform Engineering - a 360 degree view
PDF
Introduction to GitHub Actions
PDF
Docker Container
PPTX
Domain-Driven Design
PPTX
KEDA Overview
GitHub Actions in action
Red Hat Openshift on Microsoft Azure
Cloud-Native CI/CD on Kubernetes with Tekton Pipelines
Amazon DynamoDB 기반 글로벌 서비스 개발 방법 및 사례::김준형::AWS Summit Seoul 2018
DevOps Transformation in Technical
QGIS 소개 및 ArcMap과의 비교
CD using ArgoCD(KnolX).pdf
Serverless and Design Patterns In GCP
Google Kubernetes Engine (GKE) deep dive
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCD
Podman Overview and internals.pdf
금융사의 AWS기반 Digital Transformation 사례::고종원::AWS Summit Seoul 2018
Introduction to Github Actions
stupid-simple-kubernetes-final.pdf
Gitops Hands On
Platform Engineering - a 360 degree view
Introduction to GitHub Actions
Docker Container
Domain-Driven Design
KEDA Overview
Ad

Similar to Building an Android app with Jetpack Compose and Firebase (20)

PDF
Serverless Angular, Material, Firebase and Google Cloud applications
PDF
Firebase on Android: The Big Picture
PPTX
Apresentação firebase
PDF
Firebase overview
PDF
Lecture 11 Firebase overview
PDF
Using Java to interact with Firebase in Android
PDF
Android chat in the cloud
PPTX
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
PDF
TDC2016SP - Trilha Android
PPTX
Cloud Endpoints _Polymer_ Material design by Martin Görner
PPTX
LiveOps para games usando o Firebase
PDF
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
PPTX
Introduction to Firebase [Google I/O Extended Bangkok 2016]
PDF
Capstone ms2
PDF
React Native for multi-platform mobile applications
PDF
Building Microservivces with Java EE 8 and Microprofile
PDF
Level Up Your Android Build -Droidcon Berlin 2015
PDF
Parse cloud code
PDF
Gdg dev fest hybrid apps your own mini-cordova
PPTX
Angular 4 with firebase
Serverless Angular, Material, Firebase and Google Cloud applications
Firebase on Android: The Big Picture
Apresentação firebase
Firebase overview
Lecture 11 Firebase overview
Using Java to interact with Firebase in Android
Android chat in the cloud
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
TDC2016SP - Trilha Android
Cloud Endpoints _Polymer_ Material design by Martin Görner
LiveOps para games usando o Firebase
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Capstone ms2
React Native for multi-platform mobile applications
Building Microservivces with Java EE 8 and Microprofile
Level Up Your Android Build -Droidcon Berlin 2015
Parse cloud code
Gdg dev fest hybrid apps your own mini-cordova
Angular 4 with firebase
Ad

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PDF
Approach and Philosophy of On baking technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Big Data Technologies - Introduction.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation theory and applications.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
cuic standard and advanced reporting.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Cloud computing and distributed systems.
Approach and Philosophy of On baking technology
20250228 LYD VKU AI Blended-Learning.pptx
MYSQL Presentation for SQL database connectivity
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The AUB Centre for AI in Media Proposal.docx
Machine learning based COVID-19 study performance prediction
Per capita expenditure prediction using model stacking based on satellite ima...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Network Security Unit 5.pdf for BCA BBA.
Big Data Technologies - Introduction.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation theory and applications.pdf
Spectroscopy.pptx food analysis technology
cuic standard and advanced reporting.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

Building an Android app with Jetpack Compose and Firebase

  • 1. Building an Android app with Jetpack Compose and Firebase Marina Coelho Developer Relations Engineer @coelho_dev
  • 2. Firebase Authentication Firebase and Compose overview App architecture Calling async Firebase methods Firestore
  • 3. Firebase Authentication Firebase and Compose overview App architecture Calling async Firebase methods Firestore
  • 4. Drive user engagement Analytics Cloud Messaging Remote Config A/B Testing Dynamic Links In-app Messaging Improve app quality Crashlytics Performance Monitoring Test Lab App Distribution Build better apps Auth Cloud Functions Cloud Firestore Hosting Firebase ML Realtime Database Cloud Storage Extensions
  • 10. Jetpack Compose ● Android’s modern toolkit for building native UI ● Intuitive and requires less code than writing .xml files ● First stable version of Compose was launched in 2021
  • 11. Jetpack Compose @Composable fun Hello() { Column(modifier = Modifier.padding(16.dp)) { var name by remember { mutableStateOf(“”) } if (name.isNotEmpty()) { Text(text = "Hello, $name!") } } }
  • 12. Firebase Authentication Firebase and Compose overview App architecture Calling async Firebase methods Firestore
  • 13. Make it So ● Create and edit to-do items ● Add flags ● Add priority ● Add due date ● Mark as complete
  • 16. How it used to be private lateinit var auth: FirebaseAuth public override fun onCreate() { super.onCreate() auth = Firebase.auth } public override fun onStart() { super.onStart() val currentUser = auth.currentUser }
  • 17. How it is now class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { FirstComposableFunction() } } }
  • 18. How it is now class AccountServiceImpl() : AccountService { override fun getUser(): FirebaseUser? { return Firebase.auth.currentUser } }
  • 19. Firebase Authentication Firebase and Compose overview App architecture Calling async Firebase methods Firestore
  • 20. Synchronous and Asynchronous methods ● Synchronous ○ Returns directly to the caller ○ Blocks the caller thread ● Asynchronous ○ Processing in another thread ○ Return to caller thread once it’s completed
  • 21. How callback works fun authenticate( email: String, password: String, onResult: (Throwable?) -> Unit ) { Firebase.auth.signInWithEmailAndPassword(email,password) .addOnCompleteListener { onResult(it.exception) } }
  • 22. Firebase Authentication Firebase and Compose overview App architecture Calling async Firebase methods Firestore
  • 23. Authentication ● Knowing a user's identity allows your app to do many things ○ Securely save user data in the cloud ○ Provide the same personalized experience across all devices ● Firebase Authentication provides backend services, SDKs and UI libraries ● It supports different authentication methods ● Offers Anonymous Authentication
  • 25. Enabling it on the console
  • 26. Enabling it on the console
  • 27. Enabling it on the console
  • 28. Adding to code Add to app/build.gradle file: dependencies { implementation 'com.google.firebase:firebase-auth-ktx' } Sync Android project with Gradle files again
  • 29. Providing the ViewModel @HiltViewModel class LoginViewModel @Inject constructor() : ViewModel() { var uiState = mutableStateOf(LoginUiState()) private set }
  • 30. The Screen @Composable fun LoginScreen( [...], viewModel: LoginViewModel = hiltViewModel() ) { val uiState by viewModel.uiState }
  • 31. The UI State data class LoginUiState( val email: String = "", val password: String = "" )
  • 32. The Screen OutlinedTextField( singleLine = true, modifier = Modifier.fillMaxWidth(), value = uiState.email, onValueChange = { viewModel.onEmailChange(it) }, placeholder = { Text(stringResource(R.String.email)) }, )
  • 33. The Screen Button( onClick = { viewModel.onSignInClick() }, Modifier = Modifier.fillMaxWidth() ) { Text(text = stringResource(R.String.sign_in)) }
  • 34. The ViewModel fun onSignInClick() { viewModelScope.launch(exceptionHandler) { accountService.authenticate(email, password) { error -> if (error == null) { linkWithEmail() } else onError(error) } } }
  • 35. Firebase Authentication Firebase and Compose overview App architecture Calling async Firebase methods Firestore
  • 36. Cloud Firestore ● NoSQL document database in the Cloud ● Data is stored into structures called documents ● Retrieve individual or list of documents ● Listen to changes across client apps ● Offers offline support
  • 37. What a document looks like in Make it So
  • 38. Mapping data data class Task( val id: String = “”, val title: String = "", val priority: String = "", val dueDate: String = "", val dueTime: String = "", val description: String = "", val url: String = "", val flag: Boolean = false, val completed: Boolean = false, val userId: String = "" ) val task = result.toObject<Task>()
  • 39. Enabling it on the console
  • 40. Adding to code Add to app/build.gradle file: dependencies { implementation 'com.google.firebase:firebase-firestore-ktx' } Sync Android project with Gradle files again
  • 41. The service val query = Firebase.firestore .collection(TASK_COLLECTION) .whereEqualTo(USER_ID, userId) query.addSnapshotListener { value, _ -> value?.documentChanges?.forEach { val wasDocumentDeleted = it.type == REMOVED onDocumentEvent( wasDocumentDeleted, it.document.toObject<Task>() ) } }
  • 42. The ViewModel private fun onDocumentEvent(wasDocumentDeleted: Boolean, task: Task) { if (wasDocumentDeleted) tasks.remove(task) else updateTaskInList(task) } private fun updateTaskInList(task: Task) { val index = tasks.indexOfFirst { it.id == task.id } if (index < 0) tasks.add(task) else tasks[index] = task } var tasks = mutableStateListOf<Task>() private set
  • 43. The Screen val tasks = viewModel.tasks LazyColumn { items(tasks, key = { it.id }) { taskItem -> TaskItem( task = taskItem, onCheckChange = { viewModel.onTaskCheckChange(taskItem) }, onActionClick = { action -> viewModel.onTaskActionClick(openScreen, taskItem, action) } ) } }
  • 44. There's a lot more in Firestore! fun addListener( userId: String, onDocumentEvent: (Boolean, Task) -> Unit, onError: (Throwable) -> Unit ) fun removeListener() fun getTask(taskId: String, onError: (Throwable) -> Unit, onSuccess: (Task) -> Unit) fun saveTask(task: Task, onResult: (Throwable?) -> Unit) fun deleteTask(taskId: String, onResult: (Throwable?) -> Unit) fun deleteAllForUser(userId: String, onResult: (Throwable?) -> Unit)
  • 45. Firebase Authentication Firebase and Compose overview App architecture Calling async Firebase methods Firestore
  • 46. Make it So Series Github @coelho_dev Blog