简体   繁体   English

将数据同步到服务器android

[英]sync data to server android

I'm new to android sync so I really need ideas to get started. 我是android同步的新手,所以我真的需要一些入门知识。 Actually my app's requirement is like this: My app needs to connect to my database online. 实际上,我的应用程序的要求是这样的:我的应用程序需要在线连接到我的数据库。 But my android app can be used offline meaning, the user can add records to a local db, say sqlite. 但是我的android应用程序可以离线使用,用户可以将记录添加到本地数据库,例如sqlite。 And then when the user connects to the Internet, the app should automatically connect to the server and add the record the user added when he is not online. 然后,当用户连接到Internet时,应用程序应自动连接到服务器,并添加用户不在线时添加的记录。 Can you give me some considerations and ideas on how to do this? 您能给我一些思考和想法吗? I really need your help guys. 我真的需要你们的帮助。 Thanks. 谢谢。

You need to run background service like android alarm manager. 您需要运行后台服务,例如android警报管理器。 You need to check that device is connected via internet or not. 您需要检查设备是否通过互联网连接。 if device is connected via internet then sync the data to server. 如果设备通过互联网连接,则将数据同步到服务器。

Check this like to the way of data sync 像检查数据同步一样检查一下

How to sync SQLite database on Android phone with MySQL database on server? 如何将Android手机上的SQLite数据库与服务器上的MySQL数据库同步?

Thanks 谢谢

I will recommend you to go for Sync Adapter. 我建议您选择同步适配器。 See these links 看到这些链接

AbstractThreadedSyncAdapter and Creating Sync Adapter . AbstractThreadedSyncAdapter创建同步适配器

I have used them long time ago. 我很久以前就使用过它们。 I will say that it is the best approach for syncing data between device and server. 我会说这是在设备和服务器之间同步数据的最佳方法。 Usually, email apps use these sync adapters. 通常,电子邮件应用程序使用这些同步适配器。

Sample is also given there. 样品也在那里提供。 Download it if you want to go deep inside of "HOW". 如果您想深入了解“ HOW”,请下载它。

Thank You! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM