Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Weather App (2015) Concurrency and Error Handling Making Our Code Asynchronous

Mustafa Ogün Öztürk
Mustafa Ogün Öztürk
3,468 Points

Request Types

Hi there

As we see in this tutorial and OkHttp recipes there are two types. Synchronous Get and Asynchronous Get. We tried to use Synchronous one but we got error. So how to use Synchronous one and how do we decide when to Synchronous or Asynchronous types ?

Thanks

Boban Talevski
Boban Talevski
24,793 Points

I think that we should always use the asynchronous way when making web requests for data. That is not to say that the synchronous example from the okhttp site is never to be used. I'm guessing here based on my understanding so far, the synchronous okhttp example is to be used when you are manually manipulating threads in code (generally more advanced stuff) and you are actually using the synchronous request in a separate thread which will not affect the main UI thread in any way.

I would appreciate if someone could confirm this reasoning, as I don't think we should be using a synchronous web request ever in a UI application (mobile or otherwise).