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!

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 Self-Destructing Message Android App Relating Users in Parse.com Adding Checkmarks When the List is Loaded

carlo shi
carlo shi
320 Points

Wait 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
carlo shi
320 Points

How 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(); } }