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 trialNeil Gordon
8,823 PointsCan anyone assist on question 2
public int getIntExtra (String FUEL_LEVEL, -1);
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();
public int getIntExtra (String FUEL_LEVEL, -1);
}
}
2 Answers
Kevin Faust
15,353 PointsHi Neil,
mFuelLevel = intent.getIntExtra ("FUEL_LEVEL", -1);
We want to set our mFuelLevel variable to the FUEL_LEVEL constant value. and we have to specify where we are calling the getIntExtra method from. In our case it is from the "intent"
Eran Mani
3,751 PointsHey kevin,
the idea of passing data through intent is by key - value pair. since FUEL_LEVEL is our key, it will hold the value that was given to him.
now, to get that value in another activity, we ofcourse use the getIntent(); just like kevin did, for the purpose of organization, use the variable name that will hold the data that passed to the activity and assign him the value - in our case the getIntExtra, passing the KEY and giving a default value, in case you didnt get any value, or there was any kind of error.
just in case, please use Log code to show if you got the desired result in the log cat -
Log.i("Log", mFuelLevel);
hope that helps :)
Neil Gordon
8,823 PointsNeil Gordon
8,823 PointsKevin thank you , you know i did something close and deleted it. soon i will get the concept down . thank you .