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 trial

Android Build an Interactive Story App (Retired) Intents and Multiple Activities Putting Data in an Intent

stage 2 challenge 1

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 the Intent. Use the key "FUEL_LEVEL".

LaunchActivity.java
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!

    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);
      }
    });
  }
}

2 Answers

intent.putExtra("FUEL_LEVEL",mFuelLevel); should do the trick maybe.

And don't forget variable declaration is CASE SENSITIVE.

In your case let's say you bought chocolate topping for your cookies and then you try to put vanilla topping on them which you don't have. Oops that won't work :)

You have to be careful in the future:) Or you'll face the same problem:D

its correct.thank you very much .

Glad I could help.

But I still have to get to the Android Course to see what exactly is going on there:D

are you not doing Android Development?

No.

I'm still on the web design courses. My plan is to get all of the courses under my wing, since these things are very interesting for me and I can see myself in this line of work in the future.

No better way to get to the finish than with the Treehouse Team. They know what they are doing and have LOTS and LOTS of knowledge to offer.

you can do it Nejc all you need to do is to plan so that you can follow your time table and make sure what ever that you have written down you have accomplished at a stipulated time.

I don't need to plan this, 'cos I'm doing these courses every night from 10PM-2AM. So I'm doing them every night mostly - but It happens some evening I do just 2hrs 'cos I have to get up 4:30AM-5:00AM to get to work ( and I have a 1,5hrs drive to work), and a daughter 1,5 yrs old and I'm renovating our house myself.

So I'm already used to this hype all the time :)

here is my answer Intent.putExtra("FUEL_LEVEL",mFuelLevel); but l dont know where l go wrong ..help

Logan R
Logan R
22,989 Points

It took a few minutes, but I found the issue. Nejc Vukovic answer works and yours doesn't because your i is uppercase. It needs to be lowercase.

intent
Intent
Jude Dugbere
Jude Dugbere
1,211 Points

intent.putExtra("FUEL_LEVEL", mFuelLevel); you have caps in Intent use this "intent