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 an Interactive Story App (Retired) Intents and Multiple Activities Getting Data from an Intent

Maksims Visnakovs
Maksims Visnakovs
2,616 Points

Build an Interactive Story app

Hi TreeHouse community,

I can't get my head around how to correctly set mFuelLevel to the Intent value andset -1 by the fault. I tried to check documentation on developers site, but I am quite new to java and got lost in tons of information there. Please, could anyone provide a solution and a tiny explanation.

Thank you in advance.


import android.os.Bundle;

public class FlightActivity extends Activity {

  public int mFuelLevel = 0;

  protected void onCreate(Bundle savedInstanceState) {

    // Add your code below!
    Intent intent = getIntent();
    String mFuelLevel = intent.getStringExtra("FUEL_LEVEL");

1 Answer

Dean Silvestro
Dean Silvestro
Courses Plus Student 20,733 Points

Ok, you're really close!

The first thing I noticed was that you redeclared mFuelLevel in the OnCreate method. You don't need to do that, and keep in mind (this is key) that it is an int.

The answer for that line is:

mFuelLevel = intent.getIntExtra("FUEL_LEVEL", -1);

If you check the linked documentation in the challenge it will take you straight to the method you can use on the intent you created in the first step of the challenge. This method (getIntExtra) takes the String name which you provided and the second parameter -1, which is "the value to be returned if no value of the desired type is stored with the given name"

Maksims Visnakovs
Maksims Visnakovs
2,616 Points

Thank you Thomas this was very useful. I really have to pay more close attention to the documentation. After you mentioned I checked it and it was there.