Lab 3
Lab 3
Prepared by:
Ashraf Mohey
What is “Firebase Cloud messaging”?
Store and sync data with our NoSQL cloud database. Data is synced across all
clients in realtime, and remains available when your app goes offline.
2
How does it work?
The Firebase Realtime Database lets you build rich, collaborative applications by
allowing secure access to the database directly from client-side code. Data is
persisted locally, and even while offline, realtime events continue to fire, giving the
end user a responsive experience. When the device regains connection, the
Realtime Database synchronizes the local data changes with the remote updates
that occurred while the client was offline, merging any conflicts automatically
3
Firebase Database vs MySQL vs SQLite?
4
Firebase Database vs MySQL vs SQLite?
5
Firebase Database vs MySQL vs SQLite?
6
Firebase Database Pro’s vs Con’s
Pro’s:
1. If your app does run of a centralized DB, and is updated by a lot of
users – then it’s more than capable of handling the Real-Time data
updates between devices.
2. Stored in the cloud so readily available everywhere.
3. Cross Platform API (If you are using this DB with an App)
4. They Host the data. -Meaning if you are storing a lot of data, you don’t have to
worry about hardware!
5. Offline: Firebase apps remain responsive even when offline because the
Firebase Realtime Database SDK persists your data to disk. Once connectivity is
reestablished, the client device receives any changes it missed, synchronizing it
with the current server state.
6. Realtime: Instead of typical HTTP requests, the Firebase Realtime Database
uses data synchronization—every time data changes, any connected device
receives that update within milliseconds. Provide collaborative and immersive
experiences without thinking about networking code.
7
Firebase Database Pro’s vs Con’s
Con’s:
1. Unless your app runs of one centralized database updated by a vast quantity of
users, it’s a major overkill.
2. Storage format is entirely different to that of SQL, (Firebase uses JSON) so you
wouldn’t be able to migrate that easily.
3. Reporting tools won’t be anywhere near the ones of standard SQL.
4. Costs! -Limited to 50 Connections and 100mb of Storage!
5. You don’t host the data, Firebase does. And depending on which server you get
put on, viewing there up time there seems to be a lot of disruption lately.
8
Configuring Android Project with Firebase Database
9
Read/Write data to database
To read/write data to firebase in any client you always need to follow these steps:
10
Read/Write data to database
11
Task 3
You are required to integrate Firebase database into your previously created
android app in task 2 by following this tutorial
https://firebase.google.com/docs/database/android/start/
When sending push notification from FCM Console, you are required to extract
the content message and store in the database under "message" object like this
https://justpaste.it/1j3tx
To receive the notification message and extract data from it check this tutorial
https://firebase.google.com/docs/cloud-messaging/android/receive
12
Reference
https://firebase.google.com/docs/database/
13