この質問にはすでに多くのすばらしい回答がありますが、それらの回答が投稿されて以来、多くのすばらしいライブラリが出てきました。これは一種の初心者ガイドとして意図されています。
ネットワーク操作を実行するためのいくつかの使用例と、それぞれに1つまたは2つのソリューションについて説明します。
HTTP経由のReST
通常はJsonであり、XMLまたは他の何かにすることができます
完全なAPIアクセス
ユーザーが株価、金利、為替レートを追跡できるアプリを作成しているとします。次のようなJson APIを見つけます。
http://api.example.com/stocks                       //ResponseWrapper<String> object containing a list of Srings with ticker symbols
http://api.example.com/stocks/$symbol               //Stock object
http://api.example.com/stocks/$symbol/prices        //PriceHistory<Stock> object
http://api.example.com/currencies                   //ResponseWrapper<String> object containing a list of currency abbreviation
http://api.example.com/currencies/$currency         //Currency object
http://api.example.com/currencies/$id1/values/$id2  //PriceHistory<Currency> object comparing the prices of the first currency (id1) to the second (id2)
スクエアからの改造
これは、複数のエンドポイントを持つAPIの優れた選択であり、ReSTエンドポイントを、ionやVolleyなどの他のライブラリのように個別にコーディングする代わりに宣言することができます。(ウェブサイト:http : //square.github.io/retrofit/)
財務APIでそれをどのように使用しますか?
build.gradle
次の行をモジュールレベルのbuid.gradleに追加します。
implementation 'com.squareup.retrofit2:retrofit:2.3.0' //retrofit library, current as of September 21, 2017
implementation 'com.squareup.retrofit2:converter-gson:2.3.0' //gson serialization and deserialization support for retrofit, version must match retrofit version
FinancesApi.java
public interface FinancesApi {
    @GET("stocks")
    Call<ResponseWrapper<String>> listStocks();
    @GET("stocks/{symbol}")
    Call<Stock> getStock(@Path("symbol")String tickerSymbol);
    @GET("stocks/{symbol}/prices")
    Call<PriceHistory<Stock>> getPriceHistory(@Path("symbol")String tickerSymbol);
    @GET("currencies")
    Call<ResponseWrapper<String>> listCurrencies();
    @GET("currencies/{symbol}")
    Call<Currency> getCurrency(@Path("symbol")String currencySymbol);
    @GET("currencies/{symbol}/values/{compare_symbol}")
    Call<PriceHistory<Currency>> getComparativeHistory(@Path("symbol")String currency, @Path("compare_symbol")String currencyToPriceAgainst);
}
ファイナンス
public class FinancesApiBuilder {
    public static FinancesApi build(String baseUrl){
        return new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build()
                    .create(FinancesApi.class);
    }
}
FinancesFragmentスニペット
FinancesApi api = FinancesApiBuilder.build("http://api.example.com/"); //trailing '/' required for predictable behavior
api.getStock("INTC").enqueue(new Callback<Stock>(){
    @Override
    public void onResponse(Call<Stock> stockCall, Response<Stock> stockResponse){
        Stock stock = stockCall.body();
        //do something with the stock
    }
    @Override
    public void onResponse(Call<Stock> stockCall, Throwable t){
        //something bad happened
    }
}
APIがAPIキーまたはユーザートークンなどのその他のヘッダーの送信を必要とする場合、Retrofitはこれを簡単にします(詳細については、この素晴らしい回答を参照してください:https : //stackoverflow.com/a/42899766/1024412)。
1回限りのReST APIアクセス
ユーザーのGPS位置を調べ、そのエリアの現在の温度をチェックして気分を伝える「気分天気」アプリを作成しているとします。このタイプのアプリは、APIエンドポイントを宣言する必要はありません。1つのAPIエンドポイントにアクセスできる必要があるだけです。
イオン
これは、このタイプのアクセスに最適なライブラリです。
msysmiluの素晴らしい答えを読んでください(https://stackoverflow.com/a/28559884/1024412)
HTTP経由で画像を読み込む
ボレー
VolleyはReST APIにも使用できますが、より複雑な設定が必要なため、上記のようにSquareからRetrofitを使用することを好みます(http://square.github.io/retrofit/)
ソーシャルネットワーキングアプリを構築していて、友達のプロフィール写真をロードしたいとします。
build.gradle
次の行をモジュールレベルのbuid.gradleに追加します。
implementation 'com.android.volley:volley:1.0.0'
ImageFetch.java
VolleyはRetrofitよりも多くの設定が必要です。RequestQueue、ImageLoader、ImageCacheを設定するには、次のようなクラスを作成する必要がありますが、それほど悪くはありません。
public class ImageFetch {
    private static ImageLoader imageLoader = null;
    private static RequestQueue imageQueue = null;
    public static ImageLoader getImageLoader(Context ctx){
        if(imageLoader == null){
            if(imageQueue == null){
                imageQueue = Volley.newRequestQueue(ctx.getApplicationContext());
            }
            imageLoader = new ImageLoader(imageQueue, new ImageLoader.ImageCache() {
                Map<String, Bitmap> cache = new HashMap<String, Bitmap>();
                @Override
                public Bitmap getBitmap(String url) {
                    return cache.get(url);
                }
                @Override
                public void putBitmap(String url, Bitmap bitmap) {
                    cache.put(url, bitmap);
                }
            });
        }
        return imageLoader;
    }
}
user_view_dialog.xml
以下をレイアウトxmlファイルに追加して、画像を追加します。
<com.android.volley.toolbox.NetworkImageView
    android:id="@+id/profile_picture"
    android:layout_width="32dp"
    android:layout_height="32dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    app:srcCompat="@android:drawable/spinner_background"/>
UserViewDialog.java
次のコードをonCreateメソッド(Fragment、Activity)またはコンストラクター(Dialog)に追加します。
NetworkImageView profilePicture = view.findViewById(R.id.profile_picture);
profilePicture.setImageUrl("http://example.com/users/images/profile.jpg", ImageFetch.getImageLoader(getContext());
ピカソ
Squareのもう1つの優れたライブラリ。いくつかの優れた例については、サイトをご覧ください:http : //square.github.io/picasso/