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 trialRahul Vijeeth Vijayakumar
3,330 PointsI have not got a clue on this
.
import android.os.Bundle;
public class FlightActivity extends Activity {
public int mFuelLevel = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flight);
// Add your code below!
Intent intent = getIntent();
}
}
1 Answer
Chase Marchione
155,055 PointsHi Rahul,
We know that mFuelLevel is an int, since that is the data type it was declared as earlier in the class. Following the challenge's <a href=http://developer.android.com/reference/android/content/Intent.html#getIntExtra%28java.lang.String,%20int%29>Intent Documentation link</a> leads us to a method named getIntExtra, which takes two parameters. The definition of the method is 'Retrieve extended data from the intent.', which is what we're looking for. The documentation states that the first parameter to the getIntExtra method is the name of the desired item (the challenge tells us it's the "FUEL_LEVEL" key), and the second parameter is the value to be returned if no value of the desired type is stored with the given name (in other words, if there isn't an int value set yet. The challenge tells us to use -1, which is a number that is commonly used in coding as a value to store if the item we're looking for isn't found.)
Intent intent = getIntent();
intent.getIntExtra("FUEL_LEVEL", -1);
Hope this helps!