tags:

views:

172

answers:

1

I am trying to pass an integer between activities using an intent. The source activity makes the calls info.id is the selected item from a ListView. Intent intent = new Intent(myActivity.this, newClass.class); intent.putExtra("selectedItem", info.id); this.startActivity(intent); The target activity retrieves the intent using getIntent then calls int iSelectedItem = intent.getIntExtra("selectedItem", -1); iSelectedItem is always -1 instead of the value passed to putExtra. Can someone tell me what I am doing wrong or do I misunderstand the use of intents?

A: 

The problem is that info.id will be a 'long' and is not converting to an 'int'. Try

long iSelectedItem = intent.getLongExtra("selectedItem", -1)

Grant