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 Getting Data from an Intent

Shaun Kelly
Shaun Kelly
5,648 Points

Can anyone help me what i'm suppose to type in this code challenge? Stage 2 Intents and multiple Activities?.

Documentation to confusing.

1 Answer

Ratik Sharma
Ratik Sharma
32,885 Points

The first part of the challenge requires you to create an instance of the Intent class and get the intent. You can do so using the following:

// getIntent() is used to get the intent that started the Activity
Intent i = getIntent(); 

For the next part, you need to set the value for mFuelLevel using an extra that was passed to the new Activity with the intent which you just stored in the instance variable i. You can do so using the following code:

// The getIntExtra() method is what you had to look for in the docs. 
mFuelLevel = i.getIntExtra("FUEL_LEVEL", -1);

Hope that helped answer your question!