Android Build an Interactive Story App Intents and Multiple Activities Getting Data from an Intent

dimas aaron
dimas aaron
6,660 Points

get***Extra, sure it was not a String

Had a bummer, fuelLevel is an int, what the right method to have? intent.getStringExtra() was not working.

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

        Intent intent = getIntent();
        fuelLevel = intent.getIntegerExtra("FUEL_LEVEL", -1);


    }
}

2 Answers

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there! You're doing great! The method you're looking for is getIntExtra, but you're using getIntegerExtra, which doesn't exist. You had the right idea, but just spelled out the entire word "Integer" :smiley:

Hope this helps! :sparkles:

Balazs Pukli
Balazs Pukli
46,033 Points

The method name is simply getIntExtra (not getIntegerExtra)

like this:

  Intent i = getIntent();
  fuelLevel = i.getIntExtra("FUEL_LEVEL", -1);