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

Cannot understand why my code is not working.

Hi everyone who see my post In Android Basic track, in the Intent and Multiple Activity that step which I need to get data from the start intent, I cannot understand why my code is not working. I did all that I needed but still, it's not working and even I did exactly in the same way the teacher did. So could someone please help me to pass this test? Look forward to any answer :)

FlightActivity.java
import android.os.Bundle;
import android.content.Intent;
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 = new getIntent();
      fuelLevel = intent.getIntExtra("FUEL_LEVEL");

    }
}

1 Answer

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 56,130 Points

Hi there,

You don't need to call the getIntent() with new; you can leave new out. Then, you need a default value in case getting the extra value fails. The question says to use -1 as the default value. Pass this in as the second parameter like: getIntExtra("FUEL_LEVEL", -1)

I hope that helps,

Steve.

Hi and thanks for the answer So you mean I need to write something like this one?

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

Actually, I tried it but it did not work then I changed the code a little bit and got no result :(

Steve Hunter
Steve Hunter
Treehouse Moderator 56,130 Points

Yep - that's exactly right. I just pasted your code into the challenge where it says to put it and the code passes the test. I suggest restarting the challenge as the compiler might have got itself confused.