Hi,
I'm venturing into startActivityForResult for the first time and I'm running into a problem.
Activity A (ActivityMyList) launches Activity B (ActivityQuickList) waiting for a result:
Intent intentLaunchQuickList = new Intent(ActivityMyList.this, ActivityQuickList.class);
startActivityForResult(intentLaunchQuickList, REQUEST_QUICKLIST);
When a user clicks on a list item of Activity B, it returns "ql_id" to Activity A:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
QuickListItem qlItem = m_Adapter.getItem(position);
if (qlItem != null && qlItem.getQLId() != -1) {
Intent data = new Intent();
data.putExtra("ql_id", Integer.toString(qlItem.getQLId()));
if (getParent() == null) {
setResult(Activity.RESULT_OK, data);
}
else {
getParent().setResult(Activity.RESULT_OK, data);
}
finish();
}
finish();
}
Integer.toString(qlItem.getQLId()) evaluates to "1". This is important because I am not receiving "1"...
I have overridden the onActivityResult handler in Activity A with this:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_QUICKLIST) {
if (resultCode == Activity.RESULT_OK) {
Bundle extras = data.getExtras();
if (extras != null) {
int id = extras.getInt("ql_id");
}
}
}
}
Unfortunately, extras.getInt("ql_id") evaluates to "0". Why is this? It should be "1". I am clearly doing something incorrectly.
Thank you for your help