Realest Code I Ever Wrote, 72 of 100 Days…
I learned how to write data to my Realtime Database
You can find a video of this at the bottom of the page and a link to the source code here.
I added a Realtime Database to the ListOfNames Firebase project in test mode. Afterwards I wrote a few goofy entries just to get my feet wet. Once everything was complete, I imported the DatabaseReference and FirebaseDatabse classes into my project.
Next, I instantiated a FirebaseDatabase object (database) and a DatabaseReference object (myRef). Using the FirebaseDatabase object, I could obtain a reference to the database and assign it a value. In this case, the reference was named (message) with a value of (I made this myself 🙂) click below
The process above allows for reading and overwriting data. I played around and changed the argument in the myRef.setValue() method without changing the reference. This made the app overwrite the previously saved value with a new one.
This means the Realtime Database first checks for the already existing reference and, if it exists, overwrites its value. Otherwise, it creates the reference and saves the new value. While it’s less secure without authentication, it’s good for what I need at the moment.Â
Next I will experiment with reading data from the database. After that, we can see about configuring it with a ListView.
Join the mailing list to see updates like this every week!
Coding Fanatic
Happy Happy Android Image credits to Hather on DeviantArt