Reputation: 3962
I am unable to set timeout to retrofit. The code below does not work with picasso . I get a blank screen and the data and image does not load. How can I fix it with gradle:
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
COde:
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setReadTimeout(60, TimeUnit.SECONDS);
okHttpClient.setConnectTimeout(60, TimeUnit.SECONDS);
RestAdapter restAdapter = new RestAdapter.Builder()
.setClient(new OkClient(okHttpClient))
.setEndpoint(URL).build();
myapi myapi_rest = restAdapter.create(myapi.class);
myapi_rest.my_call(
sno,
new Callback<Response>() {
@Override
public void success(Response result, Response response) {
}
@Override
public void failure(RetrofitError error) {
// Log.i("Failure", "Error"+error.getMessage());
}
});
Gradle:
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile "com.squareup.okhttp:okhttp:1.6.0"
compile "com.squareup.okhttp:okhttp-urlconnection:1.6.0"
Upvotes: 3
Views: 1855
Reputation: 81569
To use your OkHttpClient with Picasso, you need to use the following code.
// Create the downloader for Picasso to use
OkHttpDownloader downloader = new OkHttpDownloader(okHttpClient);
Picasso picasso = new Picasso.Builder(context).downloader(downloader).build();
Specify the OkHttpClient for which you specified the Timeouts.
Upvotes: 1