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 an Interactive Story App (Retired) Intents and Multiple Activities Adding a Second Activity

How Intent method knows that it needs to change Activities when a user pushes the button?

How Intent method knows that it needs to change Activities when a user pushes the button? Because we did not initialize intent for Button? We just initialized that it needs to switch from MainActivity to StoryActivity?

3 Answers

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

Hello,

When you created the Intent object, I imagine you did so within the "onClickListener" of the button. This means that the button is waiting for you to click on it. Once you click on the button, it runs the code within the onClick method... which in your case is create an Intent to start a new activity, and then start the new activity.

Hello,

At the end of the video, the function startActivity(intent); is called which tells Android to start the new activity.

Thank you very much for your answers!