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 trialCarney Bernard
3,615 PointsStill Cannot Figure Challenge Out
I still can't get this challenge right. Very frustrating :( can someone please help me
"We've updated our LaunchActivity to include a fuel level(mFuelLevel) for the Spacecraft. This value needs to be passed to the FlightActivity. Add the code to pass this value along via Intent. Use the key "Fuel_Level".
// mFuelLevel is set elsewhere. // Code ommitted for brevity! int mFuelLevel= 0; mLaunchButton = (Button)findViewById(R.id.launchButton); mLaunchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Add your code in here! Intent intent = new Intent(LaunchActivity.this, FlightActivity.class); intent.putExtra("Fuel_Level", "mFuelLevel"); startActivity(intent);
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class LaunchActivity extends Activity {
public Button mLaunchButton;
public int mFuelLevel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);
// mFuelLevel is set elsewhere.
// Code ommitted for brevity!
int mFuelLevel= 0;
mLaunchButton = (Button)findViewById(R.id.launchButton);
mLaunchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Add your code in here!
Intent intent = new Intent(LaunchActivity.this, FlightActivity.class);
intent.putExtra("Fuel_Level", "mFuelLevel");
startActivity(intent);
}
});
}
}
5 Answers
Stone Preston
42,016 Pointsthe task says the key needs to be "FUEL_LEVEL". not "Fuel_Level". also, you are currently passing the string "mFuelLevel", however you need to pass the value of the mFuelLevel variable itself.
Intent intent = new Intent(LaunchActivity.this, FlightActivity.class);
// Use the correct key and pass in mFuelLevel, not "mFuelLevel"
intent.putExtra("FUEL_LEVEL", mFuelLevel);
startActivity(intent);
Jamal Shiekh
6,440 PointsJust copy and past
import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button;
public class LaunchActivity extends AppCompatActivity {
public Button launchButton;
public int fuelLevel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);
// fuelLevel is set elsewhere.
// Code ommitted for brevity!
launchButton = (Button)findViewById(R.id.launchButton);
launchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Add your code in here!
Intent intent = new Intent(LaunchActivity.this, FlightActivity.class);
intent.putExtra("FUEL_LEVEL", fuelLevel);
startActivity(intent);
}
});
}
}
Herbert Chipendo
8,544 Pointsintent.putExtra("Fuel_Level", FuelLevel);
Zach Thacker
2,089 PointsThe is found your in heart. You must learn to love again and maybe shine a light on your dark soul. Kiddo
Phidelis Murefu
820 Pointsimport android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button;
public class LaunchActivity extends AppCompatActivity {
public Button launchButton;
public int fuelLevel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);
// fuelLevel is set elsewhere.
// Code ommitted for brevity!
launchButton = (Button)findViewById(R.id.launchButton);
launchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Add your code in here!
Intent intent = new Intent(LaunchActivity.this, FlightActivity.class);
startActivity(intent);
}
});
}
}
Carney Bernard
3,615 PointsCarney Bernard
3,615 PointsThanks!
Vincent Rickey
5,581 PointsVincent Rickey
5,581 PointsHey Stone, quick question-- in the first 15 seconds of the "Sending Data to a New Activity" video, Ben states that it is not a good idea to pass class member variables from one activity into another for scalability reasons. In the video, Ben declared a new name variable in the startStory method. Why are do we pass a member variable into the intent in this code challenge?