This week i fix some bugs and learn to input the data using firebase database

Input Text instead of Email

email pattern.png

If the user input it without the email pattern (i.e. blabla@blabla.com) there will be a warning. This code will check whether the user input it with the correct pattern or not.

Open straight to the Home

auth_sign in 1.png

auth_sign in 2.png

This code will check whether the user is already do Login or not. If the user already Login and close the app, when the user open the app again it will go straight to the Home Activity instead of Login Activity.

Save Data using Firebase Database

Database that the Firebase offered is a NoSQL database, it is JSON (JavaScript Object Notation). The structure is different with SQL database, in here we cannot assign whether the attribute is Primary Key or Foreign Key or else. So in JSON we should think how the flow of data in every table will work.

database.png

This is the example that i tried, the table’s name is artist and the primary key is artistId.

save_data 1.png

save_data 2.png

This is the code how to save the data using Firebase Database.

mDatabaseReference = FirebaseDatabase.getInstance().getReference(“artists”); is to set the table that we want to input the data.

addArtist method is the method to input the data. getKey() is used to get a random String or key so it will be different with other key (unique), make it like Primary Key. Then .child() is used as the Primary Key, then setValue is to set the data in the Primary Key, in the data i set Primary Key as the ID of artist.

References:

Firebase Docs:
https://firebase.google.com/docs/auth/android/manage-users

Youtube, Simplified Coding channel:
https://www.youtube.com/channel/UC9YTuDeKzDoyOphWHtdK0jA

StackOverflow

Asking others

Advertisements