I've got problem with using database values in app. I can't find way to use them in app.
auth = FirebaseAuth.getInstance()
FirebaseUser = auth.getCurrentUser()!!
val uid = auth.getUid()!!
val fireBase = FirebaseDatabase.getInstance()
userRef = fireBase.getReference("users")
val ordersRef = userRef.child("$uid")
val valueEventListener = object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
val username = dataSnapshot.child("names").getValue(String::class.java)
val lastname = dataSnapshot.child("lastname").getValue(String::class.java)
Log.d("Data",lastname)
Log.d("Data",username)
}
override fun onCancelled(databaseError: DatabaseError) {
Log.d("Data", databaseError.getMessage()) //Don't ignore errors!
}
}
ordersRef.addValueEventListener(valueEventListener)
This is the way to retrive data from firebase. I get it in logcat :
2020-01-26 15:09:31.480 13943-13943/com.example.odpodstaw D/Data: TestLastname
2020-01-26 15:09:31.480 13943-13943/com.example.odpodstaw D/Data: TestName
I'd like to use it in App How to get it to varable? in MainActivity I've got
lateinit var name :String
lateinit var lastname :String
how to get values from database to name
and lastname
in MainActivity?
I'm just learning and I really don't know how to do this and how to use this data in my app.