An Android Data request framework

Source: Internet
Author: User

Most Android apps typically involve interacting with the server, except for some standalone applications. Since we are dealing with the server, requesting data from the server is almost necessary, and perhaps every APP has its own concrete implementation logic, but we can still abstract a common data request framework.

First:


Let's make a detailed analysis, the first vertical dashed line to the left is the Android Client, the right side is the server, background database.

In the diagram on the left, 3 android mvc activity or fragment acted as

1. In android Applications, users generally pass Span style= "Font-family:times New Roman" >view the Span style= "Font-family:times New Roman" >listview pull-down refresh, etc., so many times we are through Span style= "Font-family:times New Roman" >view controller need to request data, of course, there are exceptions, such as when loading a activity 1 step through view

2. This is a simple step, is to send HTTP requests to the server , in Android applications, generally in the form of HTTP to request data, The requested procedure is accompanied by the required parameters, in order to prevent ANR, this action pack or subsequent 3,4,5 step should be implemented in the child thread.

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

4. The client gets json format returned results, we are not able to directly use , you need to use a parser parser json data is parsed into the data model we need, that is, to 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 methods, such as the Android message mechanism.

6. The final step is for the Controller to use The data in the Models to update the View, it is important to note that the UI thread to execute.

The data request framework is probably one of the more clear logic. The data we request will inevitably have image data, then how to download the image, how to do the cache, is a big problem, here first summarize the overall data request framework, the following will summarize the picture download, caching, loading 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.