-2

In the previous Activity i did this:

int entryId = 10;
intent.putExtra("entry_id", entryId);

then in the resultant Activity

First i tried this:

entry_id = this.getIntent().getExtras().getInt("entry_id");

it always gives me the default value 0

But i changed to this:

entry_id = this.getIntent().getIntExtra("entry_id", 1);

it gives the correct value (10).

why is it so?

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
  • 1
    define constants for your intent extras name. That will avoid you spelling errors like this one. – njzk2 Sep 03 '12 at 09:33

3 Answers3

1

Try this entry_id = this.getIntent().getIntExtra("entry_Id", 1);

The change is use of I in id. It's capital in your get()

The reason is key is case sensitive

harshit
  • 3,788
  • 3
  • 31
  • 54
1

Chanage entry_Id to entry_id in your first case.

Chirag
  • 56,621
  • 29
  • 151
  • 198
0

You should use entry_id instead of entry_Id

jjLin
  • 3,281
  • 8
  • 32
  • 55