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 trialKevin Chen
2,561 PointsIs there any way that I can send the data from OKHTTP thread to main thread? So I don't have to call runOnUIThread()?
I guess enqueue() method will start a new thread to handle everything with http request. And I'm wondering is there any way that I can send the data back to main thread so I can update UI or change anything in UI thread directly without using runOnUIThread() method? Seems like I don't have the reference to the thread that handles http...
I'm trying to write the code in the following way:
mJSONData = getJsonData(latitude, longitude);
mWeather = getWeather(mJSONData);
updateDispay(mWeather);
mark gilchrist
Courses Plus Student 33,169 Pointsmark gilchrist
Courses Plus Student 33,169 Pointsyou have two options, inside your call back you can do
or you can do it with a handler
have an insatance var private Handler handler = new Handler(Looper.getMainLooper());
then in your callback