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 Getting Data from an Intent

Narain Ramjieawan
Narain Ramjieawan
639 Points

Stuck on Intent question

I am suck on this part where I have to declare an intent and get the intent that started the activity. No matter what I try I keep getting syntax errors. This is what I wrote in the editor:

I guess I am not fully understanding what is being asked of me in the question. Any help would be appreciated.

FlightActivity.java
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();
String name = intent.getStringExtra("FUEL_LEVEL");  

  }
}

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

It's asking you to retrieve the fuel level from the intent which is an int in this case, not a String. Because it's stored as an int in the Intent, you'll need to use a different method than you would a String (getIntExtra).

i dont get it whats wrong ?

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();
    int mFuelLevel = intent.IntExtra("FUEL_LEVEL",  -1);

  }
}

oh its getIntExtra dang... thanks for helping