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 trialJorge Ponce
2,252 PointsNow 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
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
Steve Hunter
57,712 PointsHi 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.
Jamal Shiekh
6,440 Pointsimport 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);
}
}
Steve Hunter
57,712 PointsThat looks fine - are you having problems with your code?
hussam jee
Courses Plus Student 929 PointsfuelLevel = intent.getIntExtra("FUEL_LEVEL", -1); it will work fine
Jorge Ponce
2,252 PointsJorge Ponce
2,252 PointsThanks a lot, i forget the number but this is my problem with the examples.
Steve Hunter
57,712 PointsSteve Hunter
57,712 Points