Sync SQLite DB on android app with the remote MySQL DB - android

I am working on an android(Java) project where I want to update my SQLite database with a remote MySQL database info.
Initially I want to create the SQLite DB as exact remote MySQL database. After that Application normally deal with the SQLite DB.
Then when application shut down and start again if any modification happened to remote MySQL database I want to sync sqlite database with the MySQL database info.
Can anyone give any idea how I can accomplish this task. Thank you

You can use android service API android.app.Service for achieving this.
You just have to run a service which will check the server database changes and if there is changes get the data from the server.
But to run that service you have to write a BroadcastReceiver which will tell service to run after specified time or after application started depending upon the requirement

Use an Account Authenticator? Alternatively use a service API (See Google I/O talk on you tube http://www.youtube.com/watch?v=xHXn3Kg2IQE fast forward to 37:37)

Related

Syncing SQLite database with remote mysql data in android

How to synchronise SQLite database and remote MySQL data in android?
To make it clear, I want to know how syncing between sqlite data and remote mysql works .. i.e., when the remote mySQL database is updated, SQLite data should also be updated without any button press or scroll down? How can I implement that using Android Studio and Wamp server ?
Thanks in advance!
I guess you can use broadcast receiver inside a service of your android application. If not you can write a service and inside the service you can use a timer to send http request to the server and keep syncing. To get a knowledege about syncing a SQlite database with remote mysql database refer to this tutorial and if you need it to happen without a button press then implement the code in the following tutorial inside a service and remember to use a timer.
TUTORIAL LINK
I don't know any way to make a mirror of your mysql database on your android's sqlite database. There are two ways I can think off when it comes to synchronizing data on your phone. The first one is by using a syncadapter. But this will only pull the data from the server and so you won't have your synchronization as soon as an update is done.
The second one is by using push notifications. With FCM, firebase cloud messaging, or GCM, google cloud messaging, you can tell your server to send a message to every phone that is connected to it. Your phone can then handle the message and synchronize itself with your database. Obvisouly in either solutions you won't have a direct access to your database as it brings huge security problems so you'll need to pass by a web server with an API to connect your application to your database.
Here are some useful links about FCM, Syncadapters, etc

Syncing local device SQLite to my mySQL server

I have an Android app on the play store which uses a local SQLite DB on the device.
However, in a planned update, I want to sync the SQLite DB with an external MySQL server with the same table and database structure, through a PHP webservice.
However, in this case, I not only want to make sure the changes in my SQLite DB are reflected in my MySQL DB, I also want to make sure that the changes in my MySQL DB get reflected in the SQLite.
Would appriciate any suggestions about how to go about it.
When you call method of web service for update external MySQL server, this method can return result of this update to Android client.
please refer this link and check first two tutorial . it may solve your problem

Direct connection and data fetching to mysql server using android

Is it possible to connect to a mysql database using android service and asynctask without using any server site scripts such as php??
My application needs to create an offline replica database, and synchronize if updated by user.
Please give suggestion and possible links, references or code.
Thanks in advance.
be aware of this :
if you connect to a remote DataBase without using a webService you will store the database login credentials inside your app. so it'll be easy to extract your login for that database and access and edit it even destroy it by decompiling your app.

I want to load my data from mysql to sqlite

is it possible to connecct, or to copy the data from mysql to sqlite? I just need to store the data from mysql to sqlite.
I used mysql because im working on an online app in android and for updating puposes. i want to copy the data from mysql to sqlite so my android app will still run even there is no internet and because of that sqlite database.
please help. thanks
If you want to connect your application with my sql server, you can use some rest service to connect with database, and return results to the calling application.
Check examples of creating, consuming rest php service by following link:
http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
http://www.helloandroid.com/tutorials/connecting-mysql-database
By these methods you can fetch data from a mysql server, further to create and perform database operation on a device database use following link:
http://www.devx.com/wireless/Article/40842

How to store data when there is no connection and synchronize when connection is available

Im actually developing an android application that can connect to MYSQL database on web query it and get latest records.
The problem is how to do when there is no connection..
I mean that an employee with an android device would record an order from the customer office but unfortunately there is no connection..How to proceed in such case?
How can we store the order locally and synchronise once the connection is available...
My problem is the method..
Thanks
I would be solving this problem in following way:
Always save save/write data to
SQLite tables (it would be good if SQLite tables structure would be the same as MySQL ones)
Check in background
Thread connection availability
As soon as you get connection - copy
all data from SQLite to MySQL
Maybe this is interesting for you to watch. Virgil Dobjanschi explains in detail what barmaley suggests.

Categories

Resources