Alaa
Alaa

Reputation: 541

manage non local sqlite database in android

I have started working with databases lately, I was able to create a local database and manage it in my Android app. Now I want to move to higher level with it but I don't know how to do it.

The users in my app need to be able to modify the database, for example insert new data in it. When a user insert new data in the database I want other users to see this change in their copy of the database.

I understand that I will need to store that database on a server or something and synchronize it with the users.

Can anyone tell me the steps to do so?

Upvotes: 0

Views: 400

Answers (1)

Bonatti
Bonatti

Reputation: 2781

You should perfom this task in steps.

First, make the local database, and use a system to know when/what changed. I usually work with triggers myself, but any "mark" is enough to synchronize.

Then, you must make a replica of that database somewhere else. Realise that maintaining the databases is a process, any change in the structure of one database must be performed in all other as well.

Finally, you must implement a method to transfer the data.

So, for an example:

db_local the database in the device. db_outside the database in the internet.

db_local.trigger -> onInsert

On the applications, check for internet, then connect to your server, then upload the same command to db_outside and run it...

In this step, you must handle connection issues, and if the SQL command was succesfully executed, you have replicated the database content.

Once you have the replicated database, inform a system (like google cloud messaging), that the database was changed, and have the other users pull the info.

Upvotes: 1

Related Questions