2015-09-25 86 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