Skip to content

Instantly share code, notes, and snippets.

@saqib-github-commits
Created April 24, 2023 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saqib-github-commits/fe11c0e94c03192a732599e3547049eb to your computer and use it in GitHub Desktop.
Save saqib-github-commits/fe11c0e94c03192a732599e3547049eb to your computer and use it in GitHub Desktop.
// Create Database Object
val database = FirebaseDatabase.getInstance("<database path>")
val databaseRef = database.reference
// Read from the database
databaseRef.addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
val value = dataSnapshot.value
Log.d(TAG, "Value is: $value")
}
override fun onCancelled(error: DatabaseError) {
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException())
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment