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 trialAdilet Zhusupbekov
1,948 PointsHow 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
Courses Plus Student 7,254 PointsHello,
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.
James Simshaw
28,738 PointsHello,
At the end of the video, the function startActivity(intent); is called which tells Android to start the new activity.
Adilet Zhusupbekov
1,948 PointsThank you very much for your answers!