Android Example Share SQLite database between 2 devices

This is just a proof of concept to show that Device A behave like a server hosting a database and Device B connects to it accessing the "shared" database. It is a response to this question.

Device A - Server (contains database)
Device B - Client (does not have database)

The idea is by implementing the Network example using AsyncStreams and B4XSerializator as explained here.

Use "Server" build configuration to compile the server.
Use "Default" build configuration to compile the client.

In client app, enter the server's IP to connect to.

You can also test with B4J.

 

Attachments

  • ShareDB.zip
    17.6 KB · Views: 324
Last edited:

aeric

Expert
Licensed User
Longtime User
Can also replace SendData with following code.

Old:
B4X:
Public Sub SendData (data() As Byte)
    If connected Then astream.Write(data)
End Sub

New:
B4X:
Public Sub SendData (Msg As Object)
    Dim data() As Byte = ser.ConvertObjectToBytes(Msg)
    If connected Then astream.Write(data)
End Sub

Then use as following:
B4X:
Dim Msg As Message = CreateMessage("REFRESH", ReadTodo)
SendData(Msg)
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…