Async Networking in Android
Async Networking in Android
(Deprecated, I never use those technology anymore.)
Table of Contents
- Background
- Source code examples
1 Background
A few days ago, people ask me a question, How to write an application which has to download the resources from the network? or Let me narrow the scope, how to write an android app, which can download the images from the Internet with HTTP protocol and insert the image into a view container like a ListView.
So, in this scenario, because the networking connections are always resources burden works, the solution is always put the heavy jobs into the background threads. Following is the equation to that problem.
I found three ways to met this equation after study that topic.
So, in this scenario, because the networking connections are always resources burden works, the solution is always put the heavy jobs into the background threads. Following is the equation to that problem.
Threads + Cache + HttpClient
I found three ways to met this equation after study that topic.
- Use AsyncTask(thread) directly, put the networking job into a background AsyncTask.
- Use ThreadPool, which is better than AsyncTask, especially in massive networking connection scenario.
- Use Volley library, which is advocated by Google, and its implementation details include the ThreadPool + Queue + Cache + HttpClient. And yes, it is the most fantastic solution, and of course the fastest one.
Comments
Post a Comment