Sunday 15 April 2012

android - In Retrofit, what is meant by "callbacks will happen on the same thread that executed the HTTP request"? -


The following says:

The callback for desktop applications will be on the same thread as the HTTP request Executed.

By studying the source (specifically RestAdapter.java ) to return it and many other similar questions (e.g.), but I Still amazed

If I have a background thread that is zero getUserPhoto (@ path ("id") id id, callback c / c> (for example) , Actually how does this library execute a callback on that thread?

If you pass the same executable to RestAdapter , then the value Take that:

  Executable service background exchanger = executors.Newcached Thread Pal (); RestAdapterBuilder.setExecutors (Background Exchanger, Background Accelerator);  

Then the callback runnab will be executed on the executable of this background, which means that you will get a callback in the same thread, otherwise the thread will stop or again Will be used and will be on the callback thread, which executes the http request.

When you are running it on the Desktop app or Android app, checks for RetroFoot , checks whether the package present from the Android SDK is present, and its For the latter, the executor (s) receives the Http request and the callback, that is, if you are running on Android, this will run the callback runable on the main thread. If you are running on non-Android then this synchronous executor (which is used for the http request) will be found, unless you pass something else this is the default platform setting that is created if You do not own


No comments:

Post a Comment