Syncing SQLite database with remote mysql data in android

后端 未结 2 1484
礼貌的吻别
礼貌的吻别 2021-02-10 14:05

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 r

相关标签:
2条回答
  • 2021-02-10 14:09

    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

    0 讨论(0)
  • 2021-02-10 14:16

    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

    0 讨论(0)
提交回复
热议问题