skip to Main Content

I’m using OkHttpClient to fetch data from remote DB and display the response to the user.
The user will never make changes to the remote DB. I’m now implementing SQL lite local DB, since I don’t think it’s good to use APIs to fetch the same data all the time (since the user will send requests frequently and the data change in remote DB will be minimal). My question is how can I update my local DB when remote DB updates/changes.

I have read that updating local DB periodically is bad practice. so, what’s the best way to do this?

2

Answers


  1. You have no way to spy on the remote DB "unless you make API calls on a regular basis you need to sample it every few minutes to truly know if it has changed" OR "you assume that every time you use the app your remote DB changed and sync it" if even this is not a viable solution for you and you need it as it updates. You need to use a Realtime DB

    Login or Signup to reply.
  2. Use socket.io.When something changes in remote db, it sends the data to the app automatically.
    Take a look at the following link: https://socket.io/blog/native-socket-io-and-android/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search