i am a newbie to android development and facing some issue with intents.
I am having a list of items displayed on screen for and want to call a different activity on click of any item in list.
I am using following code for calling a different activity on click of list item –
@Override
protected void onListItemClick(ListView lv, View view, int position, long id){
super.onListItemClick(lv, view, position, id);
//code to call activity to edit the task
Intent intent = new Intent(this, ReminderModificationActivity.class);
intent.putExtra("RowId", id);
Log.i(TAG, "row clickd --> " + id);
startActivityForResult(intent, ACTIVITY_EDIT);
}
in this above code, I am getting proper id of the list item clicked as 1,2 or 3. For the “ReminderModificationActivity” , I have this piece of code in my onCreate() function-
Log.i(TAG, "getIntent --> " + getIntent().getExtras().getInt("RowId") );
//code to check what row id have been passed
if(getIntent() != null) {
Bundle extras = getIntent().getExtras();
int mRowId = extras != null ? extras.getInt("RowId") : -1;
// Do stuff with the row id here
if(mRowId != -1){
//code if RowId valid
}
}
value received in Log.i is always 0. can anyone please help me regarding what I am missing here ? Please be detailed as i am totally new to this platform.
ans – int while capturing intents.
Thanks in Advance,
Ray
why dont you use the Intent.putExtra which passes a long value instead of a bundle?
then you just do a
and retrieve wiht a
and by the way, try to treat the data as long in both pieces of code