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
2010-09-01 13:33:53