Motivation
In Android it is highly inadvisable to do heavy lifting in the UI thread. When you even try to do some networking stuff like fetching images from a web server you might get an
android.os.NetworkOnMainThreadException
I’ve also written about it here
To work around this issue you can use a third party library like android-async-http.
Gradle Dependency
dependencies {
...
implementation 'com.loopj.android:android-async-http:1.4.9'
}
AsyncClient
AsyncHttpClient client = new AsyncHttpClient();
client.get(URL, params, new JsonHttpResponseHandler(){
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
super.onSuccess(statusCode, headers, response);
}
});
Build Request Params
RequestParams params = new RequestParams();
params.put("lat", latitude);
params.put("lon", longitude);
params.put("appid", APP_ID);