0

Hello I'm new to Android development is there any way to automatically fetch data(Retrofit2) from webserver (MySQL) to my Room database Android i have a web application and Android application sharing database records insert/update. now in my case, i want to sync the android application when there is a change or new data records inserted by the web application

as of now im using retrofit2 and room database for my android application and as per my database im using MySQL

Im creating a inventory system so it is a must for both application the realtime inventory count for each other.

Please help. thank you

R&D for this issue, using retrofit and automatic sync data

  • Does this answer your question? [Synchronizing client-server databases](https://stackoverflow.com/questions/3406891/synchronizing-client-server-databases) – Morrison Chang Jun 07 '23 at 02:44

1 Answers1

0

You have 2 platforms, website and android. When updating data on the web you want to sync for android. This requires android to know when its data is getting old compared to the actual data. Knowing that android will call back to the server to get the latest data and put it in the Database . Using the data returned by Flow from the room database will help you get the latest changes from the database. Hope to help you!

Đốc.tc
  • 530
  • 4
  • 12
  • Thank you! so i need to fetch the latest data from the web server and compare it to my room data (old) ? then put after detecting any changes ? – Emiliano Cahayon Jun 07 '23 at 06:34
  • do you have any recommendation for my app to notify that there are some data changes ? in realtime sir ? – Emiliano Cahayon Jun 07 '23 at 06:35
  • On the server you can set a version key to know if anything has changed. Every time the data from the website is pushed to the server, you increase that version and every time you go to the android app, you call the server to check that version with the version stored in the sharepreferent of the android device is the same. If the 2 versions are different, call the server to get the latest data – Đốc.tc Jun 07 '23 at 06:59
  • When you have successfully updated the new version, don't forget to save that version to android – Đốc.tc Jun 07 '23 at 07:00
  • i came up to the idea, will create a timer for every 30mins will check if there is any changes then count and display it to the UI, then call the server and update the data to the latest version. :) thanks now its not required to search how to use FCM or Firebase haha – Emiliano Cahayon Jun 07 '23 at 07:57
  • Yes, the methods are all for humans to think of. Please choose the option that best suits your project – Đốc.tc Jun 07 '23 at 08:59