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 trialahmed alghafli
3,446 PointsWe previously added a FUEL_LEVEL to our spacecraft. Now in FlightActivity, we want to get the value that we put in the
please help me with this ??
We previously added a FUEL_LEVEL to our spacecraft. Now in FlightActivity, we want to get the value that we put in the Intent. Start by declaring an Intent variable and getting the Intent used to start this Activity.
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!
}
}
8 Answers
william parrish
13,774 PointsSorry I did this non my phone and I didn't go through the first time correctly. Try getIntExtra()
william parrish
13,774 PointsThey are asking you to do two things:
Declare an Intent
Assign it the value, of the intent used to start the activity.
Which one of those are you unsure about, and did you watch the video before the quiz?
ahmed alghafli
3,446 Pointsthe second one ??!!
the first one is Intent intent = getIntent();
in fact this is the what they asked >>>?
Now set mFuelLevel the the value from the Intent. Check the Intent documentation if you need help finding the correct method to use. Use "FUEL_LEVEL" as the key and -1 as the default value.
william parrish
13,774 PointsThere is a method called. Intent.putExtra(). Which takes a string for the key, and an int for a value. Use that, with the information you just referenced. Make sure to use your "intent" .
ahmed alghafli
3,446 PointsI put this code mFuelLevel = intent.putExtra(1);
what should I do ?!!
william parrish
13,774 PointsSorry, you want to use 'getExtra'. Not put. The int is already there. You just have to get it out by key.
ahmed alghafli
3,446 PointsI changed to
mFuelLevel = intent.getExtra("FUEL_LEVEL",1);
but it said that there is a different method to get an int extra ?!!
william parrish
13,774 PointsIt may require you to specify a default value. Add another integer into the parameters, you can use 0 or 1. Or whatever you want.
"THE" Nick Grogg
2,789 Pointsso can someone just put the answer to this task up because i have no idea \
Ammon D'Addabbo
7,866 PointsmFuelLevel = intent.getIntExtra("FUEL_LEVEL", -1);
Patrick Munemo
14,892 PointsThere is the answer:
Intent intent = getIntent(); fuelLevel = intent.getIntExtra("FUEL_LEVEL", 1);
COURAGE MASUKA
676 PointsPatrick you need to use the exact value used in the question i.e -1
ahmed alghafli
3,446 Pointsahmed alghafli
3,446 PointsThanks a lot