Sync SQLite DB between 2 Devices (Tablet, Phone) ?


Active Member
Licensed User

I searched for an solution, but I found no example, hopefully you have an idea :)

I have an app that is running on my phone and on my tablet (an app to record Bloodpressure). The data is stored on both devices in an SQLite - DB (Thanks for the great tutorial btw :) ).

Now I'd like to implement a sync - feature, so that the same data is used on tablet and phone. If an user changes data in the Phone, it should sync with the data on the tablet when the app is started on the tablet.

I read something about sync - adapters in android, but to be honest, I didn't understand a word :(

Storing all data in an Online MySQL - DB is no solution, because the app should work offline as well...

I even have a clue how to start this... do you have an idea? :sign0085:

Many thanks!!


B4X founder
Staff member
Licensed User
How will the two devices share the data? Do you want them to connect to each other?

I recommend you to add a MySQL database which will be the master database. Each device will connect to it, download the new data created by other devices and upload its own new data.

You can add a time field to all database and then upload all records that are newer than the previous sync time.
Upvote 0


Well-Known Member
Licensed User
In my case, I created a serverSocket at one device and a socket at the other.
When I change data to the client's database, I send a string at the server, saying what query to perform in order to have the 'server's' database updated.
On the other hand, when we update records at the 'server' side, we have a 'refresh' button at the 'client's' side which reads data from server and performs the needed query to update its database. I used a router to create this local network.
From what I see so far, it works, but I think what Erel suggested (mySQL approach) is the best practice.
Upvote 0


Active Member
Licensed User

Thanks for the answers :icon_clap:

No, the devices should not be directly connected..

So the way over an mySQL DB on the server would be the best..

That will be complicated i guess :)

Then I would need an unique ID for the Database-Entrys for each user... I guess, the GMail-adress from the google-market account would be the best for this. Is it possible to get this adress in B4A?
Upvote 0