简体   繁体   English

如何从中心数据库获取数据并存储在android sqlite数据库中?

[英]How to fetch data from center database and store in android sqlite database?

I want create an Android App in which any user can add some information in some central database and it gets visible to all other users using this App. 我想创建一个Android应用程序,其中任何用户都可以在一些中央数据库中添加一些信息,使用该应用程序的所有其他用户都可以看到该信息。

So, I want to maintain a centralised database and update the App local database (sqlite database) using this centralised datbase. 因此,我想维护一个集中式数据库并使用此集中式datbase更新App本地数据库(sqlite数据库)。

So, can anyone please help me in this? 那么,有人可以帮我吗? I want some idea or code example or pointer to know the things... 我想要一些想法或代码示例或指针来了解这些内容...

PS: I am very new to the Android App development. PS:我对Android App开发非常陌生。 So, if I would have missed any required information , plesae let me know. 因此,如果我错过了任何必需的信息,请plesae通知我。

You'll have to store your remote database on a remote database server. 您必须将远程数据库存储在远程数据库服务器上。 You can use a simple database like MySQL for this. 您可以为此使用一个简单的数据库,例如MySQL。 Then you'll have to create REST API's (by writing server side code using a language like PHP, Ruby, Python etc) that your Android app can consume to obtain the data from the db. 然后,您必须创建REST API(通过使用PHP,Ruby,Python等语言编写服务器端代码),Android应用程序可以使用该API来从数据库获取数据。

There are other options that avoid REST API's as well. 还有其他选择也可以避免使用REST API。 See: 看到:

How to get from a MySql server to an Android app? 如何从MySql服务器转到Android应用程序?

See here for a beginners tutorial on REST: 请参阅此处以获取有关REST的初学者教程:

http://net.tutsplus.com/tutorials/other/a-beginners-introduction-to-http-and-rest/ http://net.tutsplus.com/tutorials/other/a-beginners-introduction-to-http-and-rest/

Once you've done that, You have to create Threads or AsyncTasks in your Android app that will call the API's and parse the obtained data (Usually data is sent in JSON format). 完成此操作后,您必须在Android应用程序中创建线程AsyncTasks ,这些线程AsyncTasks将调用API并解析获取的数据(通常,数据以JSON格式发送)。 Then you can store the parsed data in your local android SQLite database and access it. 然后,您可以将解析的数据存储在本地android SQLite数据库中并访问它。

Android db tutorial: Android db教程:

http://www.vogella.com/articles/AndroidSQLite/article.html http://www.vogella.com/articles/AndroidSQLite/article.html

Android Async tasks and threads tutorial: Android Async任务和线程教程:

http://www.vogella.com/articles/AndroidPerformance/article.html http://www.vogella.com/articles/AndroidPerformance/article.html

Android JSON tutorial: Android JSON教程:

http://www.vogella.com/articles/AndroidJSON/article.html http://www.vogella.com/articles/AndroidJSON/article.html

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

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