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 Intents and Multiple Activities Getting Data from an Intent

Now set fuelLevel to the value from the Intent. Check the Intent documentation if you need help finding the correct meth

hello i put this intent.putExtra("FUEL_LEVEL", fuelLevel);

help

FlightActivity.java
import android.os.Bundle;

public class FlightActivity extends AppCompatActivity {

    public int fuelLevel = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flight);
      Intent intent = getIntent();
Intent putExtra (String"FUEL_LEVEL", 

        // Add your code below!

    }
}

3 Answers

Hi Jorge,

You want to pull the value you sent through the intent into your fuelLevel variable.

You've declared the intent now you need to assign a value into fuelLevel(). For this, you call the getIntExtra method on the intent because you sent an integer through the intent.

The getIntExtra() method needs two parameters. First, the key of the key/value pair. This allows access to the the value which is what you're after. In this case, the key is "FUEL_LEVEL". The method also needs a fail value in case the key is wrong. The challenge wants a default of -1.

That all looks like:

        // Add your code below!
        Intent intent = getIntent();
        fuelLevel = intent.getIntExtra("FUEL_LEVEL", -1);

I hope that helps.

Steve.

Thanks a lot, i forget the number but this is my problem with the examples.

:+1: :smile:

import android.os.Bundle;

public class FlightActivity extends AppCompatActivity {

    public int fuelLevel = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flight);

        // Add your code below!
  Intent intent = getIntent();  
  fuelLevel = intent.getIntExtra("FUEL_LEVEL", -1);






    }
}

That looks fine - are you having problems with your code?

fuelLevel = intent.getIntExtra("FUEL_LEVEL", -1); it will work fine