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 Implementing Designs for Android Updating Other GridViews Updating the Recipients Activity

Why are we leaving in defunct code in the query callback method?

Inside the callbacks to parse, because our new adapters are using the mFriends list of ParseUsers directly, it doesn't seem like we need the for loop to get the string array for usernames in order to keep the ArrayAdapter. I've commented that code out

String[] usernames = new String[mFriends.size()];
for(int i = 0; i < mFriends.size(); i++) {
   usernames[i] = mFriends.get(i).getUsername();
}

seems pointless with our custom adapter. Am I wrong?

Nicolas

1 Answer

Henry Goh
Henry Goh
20,201 Points

Hi Nicolas,
If the username array is being used in the future, it is better to have a variable of usernames stored in a variable rather than having to access the Friend object and get the username.

e.g.: For username[i], you get the username directly from the array, whereas mFriends.get(i).getUsername(), you have to get the Friend object from the Friends array, then get the username from the Friend object.

Hope this helps

I could see that Henry, but having that code loop run seems like it wastes valuable processing power, the scope of the variable is the callback so nothing else could use it, and to comment it out would boost performance and save it if we need the function in the future.

I could see that Henry, but having that code loop run seems like it wastes valuable processing power, the scope of the variable is the callback so nothing else could use it, and to comment it out would boost performance and save it if we need the function in the future.

Henry Goh
Henry Goh
20,201 Points

I agree, since there is no use for this block of code, then it is best to comment it out.
If it is still not being used by the end of this project, maybe you can highlight this issue to Ben.
The less code, the better.

Just finished, thus why I'm bringing it up. Ben Jakuben