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 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.