Syncing SQLite database with remote mysql data in android - 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

Related

How to validate Offline cached data and data coming from API

I am trying to make an app in which I am going to use room database for offline data caching and using NodeJs and MongoDB as a backend service.
What I am going to do is when app first opens it fetches data from server and stores in room database from where it shows in database.
My problem is whenever some new data is updated on server how would I know whether it is available in room database and when to fire server request.
Someone please let me know how can achieve this any help would be appreciated.
THANKS
You are going to need to implement some sort of routine where you can check and validate (update) the data. However, this will depend on the importance of the data and rather if it should be updated and how often.
These are some of the solutions you can look at:
Long/short polling - Client Pull
WebSockets - Server Push
Server-Sent Events - Server Push
I would probably use some sort of real-time communication (web sockets) or use a real-time database to notify the app of changes when something needs to get updated. That said it would also depend on the technology, for instance, Firebase already offers offline caching.
You can achieve this functionality in multiple ways
Configure firebase notification in your app, whenever any server side data update happen just trigger a notification, based on that you can call api and store data in room.
Maintain some version code related to updated server side data in your api, based on that version code you can write logic for storing data in room.

How to share my to do list app data between 2 android devices

I am working on to do list app and I saved data in SQLITE and I want to share app data to my friend who install my app but he away from me with along distance so I can't use Bluetooth and socket.
Please help me and thanks in advance .
https://cloud.google.com/solutions/mobile/firebase-app-engine-android-studio
You could have used your own backend web service and send it through with JSON data. If you do not want to create a backend service, just use firebase cloud real time database which is very suitable for your project. Firebase Database Instead of creating local SQLite database, save your data into the database which is in the cloud, whenever your friend open the activity or application, fetch data from backend service/firebase database whatever you like

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.

Android SQLite to My MySQL Web Server?

I have been learning SQLite on Android and have done some tutorials on how to use it.
There is a question that I want to ask.
Is there a way to make my app connect to my MySQL database in a remote web server of mine so that it can read data and also write data to the database?
From what I've researched, SQLite cannot be used remotely and I would need some kind of Web service in between?
It's not easy to create a connection to MySQL from Android, if it's not impossible. With that, it's also not safe if for example someone decompiles your app they have access to your whole MySQL database if you don't limit it enough.
For those reasons, you can better use a (for example) PHP webservice to which the Android application sends all their requests. An example is available at http://www.helloandroid.com/tutorials/connecting-mysql-database.
I also suggest you use Android Asynchronous Http Client so you don't have to deal with connectivity issues and AsyncTasks yourself.
You can refer to this tutorial but you do need a web-server for it.
Request mechanism
Android App ----> webserver ------> database (mysql)
Respond mechanism
Android App <---- webserver <------ database (mysql)
Android App will use JSON or other to get the data and display it
You have to use Sqlite database and web Services both. First you have to save the data in local database i.e. SQLite database and then send this data to your server using web services and vice versa.
this link for web services
and this link for SQlite will help you understand.
Thanks.

Sync SQLite DB on android app with the remote MySQL DB

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)

Categories

Resources