2015-09-25 47 views
-1

我是网络端的新手,想要学习LoopJ AndroidAsyncHttp是如何工作的,我已经下载了项目并在构建完成后得到了它的工作。 现在我loogkin为LoopJ AndroidAsyncHttp的任何链接或教程,以获得基本的想法之前,我可以开始浏览项目代码。LoopJ的基本教程AndroidAsyncHttp

m也学习机器人,所以它很难让我理解代码而不知道基础知识。

请指导我选择更好的方法来理解它。

我的工作项目是:https://github.com/loopj/android-async-http

+0

你阅读本:http://loopj.com/android-async-http/ –

+0

使用改装相反,http://square.github.io/retrofit/它具有异步请求 – NaviRamyle

回答

0

使用OkHttp

Let me show a simple example. 

import com.squareup.okhttp.OkHttpClient; 
import com.squareup.okhttp.Request; 
import com.squareup.okhttp.Response; 
import java.io.IOException; 

public class GetExample { 
OkHttpClient client = new OkHttpClient(); 

String run(String url) throws IOException { 
Request request = new Request.Builder() 
    .url(url) 
    .build(); 

Response response = client.newCall(request).execute(); 
return response.body().string(); 
} 

public static void main(String[] args) throws IOException { 
GetExample example = new GetExample(); 
String response = example.run("https://raw.github.com/square/okhttp/master/README.md"); 
System.out.println(response); 
} 
} 
0

就像NaviRamyle所说的,你可以使用Retrofit作为你的异步HTTP请求的解决方案。另外,请看Google的Volley。一个很好的例子/教程,让我使用和享受抽射被Androidhive的基本凌空教程:

http://www.androidhive.info/2014/05/android-working-with-volley-library-1/

默认情况下,所有的请求都是异步的,并通过一个回调架构,您可以轻松地在你的应用程序中实现管理。

最好的问候,

+0

尽管这可能会回答这个问题,但[这将是更可取的](http://meta.stackoverflow.com/q/8259)在这里包含了答案的基本部分,并提供了供参考的链接。 – IKavanagh