Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?