I just made a simple JSON parsing program with Okhttp now what is Callback in Response of OKhttp and Why we use this ?
OkHttpClient okHttpClient=new OkHttpClient();
Request request=new Request.Builder().url(url).build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
}
});
Callbacks are used for asynchronous calls, in this case it will either return you the result from your network call to the url(Json/Xml data) in onsuccess or if there is an error onfailure will be called.
Error could be if connection didn't got through or connection timeout, response timeout, resource/address not valid, etc.