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 trialcarlo shi
320 PointsWait the result of both two asnyc task
In this video we request "all users" and "user friends" by two async task.
In the callback of "all users" we called addFriendCheckmarks() method.
But if i have more than ten thousands users and thousand friends. Both of these two async task takes a long time.
It would be better to call all these async task in the same time in OnResume() method, and before the set of the check marks (getListView().setItemChecked(i, true);) , we can check if the "all users" request already returened the result.
My question is how to implement this(Async the result of two asnyc task) ? Should I set two member variable to check the return state of two async task or there are some better way to do this? Thanks
1 Answer
carlo shi
320 PointsHow about this solution?
boolean b1 = false; boolean b2= false;
callback1( done{ b1 = true; asyncTwoFunction(b1,b2) } )
callback2( done{ b2 = true; asyncTwoFunction(b1,b2) } )
asyncTwoFunction(b1,b2){ if(b1 && b2){ doSomeThing(); } }