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

Savitha Narayana
Savitha Narayana
1,799 Points

How to get the Intent?

I am gettint compile error

FlightActivity.java
import android.os.Bundle;
import android.content.Intent;

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 data = intent.getStringExtra("FUEL_LEVEL");

  }
}

3 Answers

If I get this right, you're are stuck at step one of the challenge. The task is written a bit confusing, but you are required to just declare that intent variable. Nothing else. Meaning the only line of code you need, in order to complete task 1, is:

Intent intent = getIntent();

EDIT: I notice you're trying to use getStringExtra. You are about to encounter another problem in task two. Make sure you pay attention to what type of variable you're using throughout the challenges. In the videos, you do the examples with String. What about the challenges? Is getStringExtra the method you need here?

Harry James
Harry James
14,780 Points

Marking as Best Answer - Asker has regarded this as solved

Savitha Narayana
Savitha Narayana
1,799 Points

Thank you Kristian , i figured out :)

Would you mind marking the thread as "solved" so others can find help if needed?

:smile: Not what I ment. You have to select "Best Answer" and the thread will be marked.