Reputation: 1006
Today I was just doing some research on Retrofit by our very own Jake Wharton, so I did something like this
RetroClass.getClient().getSomeData(param, new Callback<Model>(){
@Override
public void failure(...){/*blah*/}
@Override
public void success(Model response, Response notUsed)
{
try
{
Thread.sleep(10000);
}
catch(Exception e){e.pST();}
}});
I expected a ANR, but the flow is executing fine, Jake Wharton mentioned in this post Does Retrofit make network calls on main thread? "As it states in the answer, if you use the second pattern (last argument as a Callback) the request is done asynchronously but the callback is invoked on the main thread. By default Retrofit uses a thread pool for these requests."
that the call back is executed on the main thread, whats happening here, any insights ? Why isnt Thread.sleep() not causing an ANR here...? Im baffled....
Upvotes: 1
Views: 2797
Reputation: 20143
Yes by default for the Android platform the Callback
Executor
used is MainThreadExecutor.
Make sure you're not overriding the default implementation when creating your RestAdapter by doing something like this
RestAdapter restAdapter = new RestAdapter.Builder()
.setExecutors(new MyHttpExecuter(), new MyCallbackExecutor()) { // watch out for this
.build()
If you override the default Callback
Executor
by setting your own then you won't get the default behaviour.
Upvotes: 2