Need to transfer the Firebase data to MySQL and synchronize - android

I am creating an Android project and in our app, we are going to store the abstract user data and we are creating in Firebase because of its feature of real-time updating. But for doing data analysis we need to store the data in some database, for doing the query operation we have thought of MySQL but on searching regarding my query I have found it can be done but it requires NodeJS support on the server which is not provided by our hosting provider. Is there some other way to handle this problem?

Related

Android Room and Firebase in a MVVM Architecture - Offline First Application

Can Android Room Database be used as an (offline/local data source) and Firebase Database as the (online data source) in an MVVM repository (gluing the data together) refer to the figure below. Having the same database table and column setup. The application can be used and make changes offline and later sync the modified version on firebase when the internet is available.
Figure 1: MVVM ROOM FIREBASE FIGURE
Figure 2: Data Layer on Repository
Problem: I already have a room database following MVVM architecture but can't figure out how to integrate firebase as my online data source and synch to tables.
Knowing: Android's Room database is a SQL database, while Firebase's Realtime Database is a NoSQL database.
If this is possible, how firebase can be set on as an online data source connected to the repository in a simplified version or an article I can follow? Or is there an alternative wherein, a database is suggested instead?
Can Android Room Database be used as an (offline/local data source) and Firebase Database as the (online data source) in an MVVM repository?
For sure it can be, but I cannot see any reason why you would do that. Why? Because the Realtime Database has its own offline persistence mechanism. This means that your application will continue to work even if the user device temporarily loses its network connection. Besides that, all the cached data is available while the device is offline and Firebase resends any writes when the internet connectivity is restored.
The application can be used and make changes offline and later sync the modified version on firebase when the internet is available.
You're describing exactly how the Realtime Database works if you enable disk persistence using the following line of code.
FirebaseDatabase.instance.setPersistenceEnabled(true);
If this is possible, how firebase can be set on as an online data source connected to the repository in a simplified version or an article I can follow? Or is there an alternative wherein, a database is suggested instead?
I don't see why would you add an extra level of complexity when the Realtime Database already handles that for you. However, if you still want to do that, then you have to check inside the ViewModel class if the device is connected to the internet or not. And according to the connection state, you should request the data either from the Realtime Database or from Room.
Here are some useful links:
How to read data from Room using Kotlin Flow in Jetpack Compose?
How to read data from Firebase Realtime Database using get()?
If you consider at some point in time try using Cloud Firestore, then I also recommend you read the following resource:
How to read data from Cloud Firestore using get()?
Remember, that in Cloud Firestore, for Android and Apple platforms, offline persistence is enabled by default.

How to validate Offline cached data and data coming from API

I am trying to make an app in which I am going to use room database for offline data caching and using NodeJs and MongoDB as a backend service.
What I am going to do is when app first opens it fetches data from server and stores in room database from where it shows in database.
My problem is whenever some new data is updated on server how would I know whether it is available in room database and when to fire server request.
Someone please let me know how can achieve this any help would be appreciated.
THANKS
You are going to need to implement some sort of routine where you can check and validate (update) the data. However, this will depend on the importance of the data and rather if it should be updated and how often.
These are some of the solutions you can look at:
Long/short polling - Client Pull
WebSockets - Server Push
Server-Sent Events - Server Push
I would probably use some sort of real-time communication (web sockets) or use a real-time database to notify the app of changes when something needs to get updated. That said it would also depend on the technology, for instance, Firebase already offers offline caching.
You can achieve this functionality in multiple ways
Configure firebase notification in your app, whenever any server side data update happen just trigger a notification, based on that you can call api and store data in room.
Maintain some version code related to updated server side data in your api, based on that version code you can write logic for storing data in room.

How does Firebase Database Instances retrieve data in realtime?

I just built my first app. It's an Group Messaging App for which I used Firebase Realtime Database. I followed this tutorial to build my app.
The chat is working flawlessly and in realtime ie any changes into the Database are retrieved and reflected within seconds on my app. Actually, being bit curious, I didn't just copy paste all those code lines instead I'm trying to understand meaning behind each statement. So, I'm confused with one of my doubts:
How does this work in realtime (chats pop up immediately)? I was reading about Firebase Database here and they mention ValueEventListener is used to update app data in realtime but what's used here?
From the documentation:
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.
Network-wise this is achieved through WebSockets, which is used both on the server and in the client side Firebase library.
Additionally, the "Realtime Database API is designed to only allow operations that can be executed quickly".
Edit: The Firebase client library sets up one WebSocket to communicate with the Realtime Database, which is used for all the communication with the Realtime Database, both reading/subscribing and updating/pushing (unless you use the REST API).
Edit 2: In the tutorial you did you used the FirebaseListAdapter which abstracts away how the data synchronization is done. It's fourth parameter is a reference to a Realtime Firebase Database location that it will sync with (using WebSocktes), and populate the list for you. It takes each entry of the synced data and puts it into new Java objects of the model class you provide as second argument, namely ChatMessage.class.

Syncing SQLite database with remote mysql data in android

How to synchronise SQLite database and remote MySQL data in android?
To make it clear, I want to know how syncing between sqlite data and remote mysql works .. i.e., when the remote mySQL database is updated, SQLite data should also be updated without any button press or scroll down? How can I implement that using Android Studio and Wamp server ?
Thanks in advance!
I guess you can use broadcast receiver inside a service of your android application. If not you can write a service and inside the service you can use a timer to send http request to the server and keep syncing. To get a knowledege about syncing a SQlite database with remote mysql database refer to this tutorial and if you need it to happen without a button press then implement the code in the following tutorial inside a service and remember to use a timer.
TUTORIAL LINK
I don't know any way to make a mirror of your mysql database on your android's sqlite database. There are two ways I can think off when it comes to synchronizing data on your phone. The first one is by using a syncadapter. But this will only pull the data from the server and so you won't have your synchronization as soon as an update is done.
The second one is by using push notifications. With FCM, firebase cloud messaging, or GCM, google cloud messaging, you can tell your server to send a message to every phone that is connected to it. Your phone can then handle the message and synchronize itself with your database. Obvisouly in either solutions you won't have a direct access to your database as it brings huge security problems so you'll need to pass by a web server with an API to connect your application to your database.
Here are some useful links about FCM, Syncadapters, etc

Firebase online to Android offline datastore

I am building a mobile app to allow for real time messaging, befriending users, creating groups to both chat and share images with, as well as creating events where users can invite one another.
I have chosen to use Firebase as the online back-end. But, given Firebase uses a NoSQL data model, while Android SQLite uses SQL, when saving data offline in Android what is the conventional way to handle this? Is there a simple way to convert or simply save from NoSQL to SQL, or do I need to build a converter?
(This is especially important for the events, as once created, they must be scheduled in the AlamManager, giving users alerts upon event time)
While you could implement your own solution, truth is, you do not need to build anything from scratch.
There are free Android libraries which could help you. I would recommend you:
SimpleNoSQL
The transition from Firebase to SimpleNoSQL is pretty straight forward, and is mostly the same as if you were using any form of SQL:
1) You get the data from your remote db: you can get this trough a request to your remote server, it doesn't matter what language you are using as long as it can return a response you can catch.
2) You save said data to your local NoSQL db: once you have the information requested, it is up to you what to do with it. You could save it to a TXT file, a SQLite db, NoSQL db, save it to the SharedPreferences, etc.
Hope that helps.

Categories

Resources