Search code examples
androidlistviewcursorbundle

How to send long value from one activity to another?


I am using ListView in my activity. on any list item seleted(ID) it should display the entire row(associated with ID), in another activity. I used bundle object to pass the long value using "putExtra". but that did not work either. may I know how could I get it done.?

1st activity :

Bundle dataBundle = new Bundle();
dataBundle.putLong("ID",id);

Intent myIntent = new Intent();
myIntent.setClassName("com.mink7.databaseapplication", "com.mink7.databaseapplication.OnItemClickFromLV");
myIntent.putExtras(dataBundle);
startActivity(myIntent);

2nd activity :

Bundle extras = getIntent().getExtras(); 

if(extras !=null)
{
    long idd = extras.getLong("ID",0);
    Cursor c=db.getName(idd);
    final String name_ret = c.getString(c.getColumnIndex("name"));
    final int age_ret = Integer.valueOf(c.getString(c.getColumnIndex("age")));
    final String city_ret = c.getString(c.getColumnIndex("city"));
    t1.setText(name_ret);
    t2.setText(age_ret);
    t3.setText(city_ret);
}

Solution

  • Just add the long directly, like intent.putExtra("ID",value) the extras are already a key value pair. Then the code for receiving the values on your second activity should be working.