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

Toast Notifications

Hi,

Doing the code challenge. The question is as follows :

Initialize the Toast variable using the static makeText() method of the Toast class. Use the ‘this’ keyword for the first parameter, the text "All done!" for the second parameter, and the constant Toast.LENGTH_LONG for the third parameter.

My answer

Toast allDoneToast; Toast welcomeToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG);

Please help

4 Answers

Let's work through the problem together.

You are given:

Toast allDoneToast;

Then the first sentence reads:

"Initialize the Toast variable using the static makeText() method of the Toast class."

So it wants you to initialize the Toast variable that was given to you (allDoneToast). Note that it's telling you to use the "makeText()" method which is static. This let's you know that you don't initialize it like most other objects (aka: You don't use the 'new' keyword for statics) Which is done like this:

allDoneToast = Toast.makeText();

Then it tells you:

" Use the ‘this’ keyword for the first parameter, the text "All done!" for the second parameter, and the constant Toast.LENGTH_LONG for the third parameter."

Which is pretty self explanatory.

allDoneToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG);

Which gives you the final answer of:

The answer is:

Toast allDoneToast;
allDoneToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG);

Keep coding!

just Toast.maketext

Thank You sir :)