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 Intents and Multiple Activities Getting Data from an Intent

Will Sokolowski
Will Sokolowski
2,292 Points

INTERACTIVE STORY - INTENT HELP

I'm having a hard time with intent in Build and Interactive story. It's task 2 of 2, and wants me to do this.

Now set fuelLevel to the value from the Intent. Check the Intent documentation if you need help finding the correct method to use. Use "FUEL_LEVEL" as the 'name' and -1 as the 'defaultValue'.

I've tried to do everything possible, similar to the code that's in my app....just like every single other video...and i'm not sure what i'm doing wrong.

I've tried something similar to this String name = intent.getStringExtra("Name"); and it won't take that....using the appropriate values of course. I can't go back now to copy my code, there's no way to get my code from the activity and not close this question here. This is the first time I've been stuck, and I would really appreciate the help. Thanks!

FlightActivity.java
import android.os.Bundle;

public class FlightActivity extends AppCompatActivity {

    public int fuelLevel = 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", 1);

    }
}

1 Answer

public class FlightActivity extends AppCompatActivity {

    public int fuelLevel = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flight);

        // Add your code below!
      Intent intent = getIntent();
  fuelLevel = intent.getIntExtra("FUEL_LEVEL", -1);

    }
}

Thank You..