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 Capturing Photos and Videos Selecting a Photo from the Gallery

Why did Ben used getString when making the Toast?

Why did Ben used getString() method when making the Toast? I think it's not needed there.

2 Answers

Ben was using the getString() method to retrieve a string resource from a resource XML file. This may seem quite strange, but if your app supports multiple languages, you can have a different string.xml file for each language. For instance the below supports a default language(with no dash after the "values" folder name), Spanish and French.

MyProject/
    res/
       values/
           strings.xml
       values-es/
           strings.xml
       values-fr/
           strings.xml

if you then use the getString() method within your app, the device will pick the correct strings.xml based on the users currently selected language.

It's a really good practice to get into!

Hello,

I think that the makeText(Context context, CharSequence text, int duration) method was used instead of the makeText(Context context, int resId, int duration) method was mostly for familiarity and habit. I believe that both should be able to accomplish the same task, but I believe there are also other methods that don't give the option so the getString() method is the only option and you might as well stay consistent and use getString() everywhere instead of mixing it up.