An Android Data request framework

Source: Internet
Author: User

Most Android apps typically involve interacting with the server, except for some standalone applications. Since you're dealing with the server, requesting data from the server is almost something you must do, and perhaps every APP has its own detailed implementation logic. But we can still abstract a common data request framework.

First:


Let's take a detailed look at the analysis. The first vertical dashed line on the left side is the Androidclient. The right side is the server, background database.

On the left side,3 Gray modules are mvcin Android (for a brief introductionto the MVC pattern in Android) ), in which Activity or Fragment acts as the Controller 's role.

Next, we describe the following specific steps:

1. In android application. Users generally interact with view listview pull-down refresh, etc., so very often we are through view controller There is a need to request data, of course, there are exceptions, for example when loading a activity 1 step through view

2. This step is simpler. is to send an HTTP request to the server . In an Android app, the data is typically requested via http , with the required number of parameters attached during the request. In order to prevent ANR. This action pack or perhaps 3,4, and5 steps should be implemented in a child thread.

3.server returns data to the client. This is usually a lightweight, easy-to-transmit JSON format, and of course, in XML format.

4.client get json Format the returned results, We are not able to use it directly. You need to use a parser parser json data is parsed into the data model we need. You get the models The Cache

5. When the data is parsed into Models ,theController can use it to update the view, and after parsing the data, a mechanism is generally set up to notify Controller. There are many ways to do this, such as Android 's messaging mechanism.

6. The final step is that the Controller uses The data in the Models to update the View. It is important to note that the UI thread must be run.

The data request framework is probably this, a clearer logic. The data we request will inevitably have image data, then how to download the image, how to do the cache, is a very big problem, here first summarize the overall data request framework, may summarize the picture download, caching, loading framework.


An Android Data request framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.