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

Troels Zink Kristensen
Troels Zink Kristensen
1,014 Points

I have no idea what to do with this exercise.. It is not like what I was teached in the videos..

I thought I should write the code like the teacher and myself did during the videos, but that doesn't work. So I don't know what do to. You guys confuse me with the differences between the videos and the text editor you want me to do exercises in.

It's missing a private void in the editor compared to the video..

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", FUEL_LEVEL);
        startActivity(intent);
      }
    });
  }
}

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

For putExtra() the first argument is the data, or information, you want to send. You want to send the current fuel level which is stored in the variable mFuelLevel. Next is the name or label to call the data, often referred to as a key. The key here is always a string. Of course it can be a plain string literal, variable or constant. For the challenge we can make it easy an use the literal name.

intent.putExtra(mFuelLevel, "FUEL_LEVEL");
Troels Zink Kristensen
Troels Zink Kristensen
1,014 Points

Thank you very much. I just couldn't figure out what to do at the moment, but now I know. :)