Skip to content
Advertisement

Getting the current User information from Firebase Realtime Database

I developed a login app in Java where the user can login using their emailaddress and password. This works fine so far, but I have the problem that my UserModel.java is null when I get to my home activity. This also makes sense to me since Firebase Auth only checks the email and password and does not select the relevant information from the realtime database. I have therefore inserted a datasnapshot, this also works in the intended way since the system outputs the desired name.

My question is now how can I assign this datasnapshot to my UserModel so that my UserModel is no longer null (is it?!). In the last part of my HomeActivity you can see a String which should contain the Users Name, however even if I log in with an existing account this String is only showing the “Example Name”. Due to the fact that the system is printing out the correct name I believe the DataSnapshot works as it should.

Thanks for your help!

part of my HomeActivity

JavaScript

UserModel

JavaScript

part of my Common class

JavaScript

Advertisement

Answer

I have now put both parts of the code together and was able to display the string with the correct name. However, the Common.CurrentUser is not initialized what is not a problem as long as the Attributes are alright.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement