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 Self-Destructing Message Android App Self-Destruction Deleting Partial Data for One Recipient

Alex Feinberg
Alex Feinberg
2,025 Points

Redundant code in InboxFragment

In the final step (removing the current user from the recipient list), I believe the project code has a redundancy.

This code: ids.remove(ParseUser.getCurrentUser().getObjectId());

And this code: ArrayList<String> idsToRemove = new ArrayList<String>(); idsToRemove.add(ParseUser.getCurrentUser().getObjectId()); message.removeAll(ParseConstants.KEY_RECIPIENT_IDS, idsToRemove);

Both have the effect for removing the current user's ID from the list of recipient IDs in the ParseObject. Either one is adequate, if you do both, the second is a no-op.

2 Answers

Alex Feinberg
Alex Feinberg
2,025 Points

Yes. I tested both approaches individually and together and it works fine in all cases. While, the first approach of simply using the remove method on the array is simpler and cleaner, the second approach provides some useful exposure to the parse APIs.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Great feedback - thanks for sharing!

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Good catch! Have you tested to verify?