Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onActivityResult Intent data not correct

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

like image 405
Andrew Avatar asked Mar 11 '26 19:03

Andrew


1 Answers

Ah, nevermind. I'm putting a String into the bundle and pulling an int out.

like image 111
Andrew Avatar answered Mar 13 '26 11:03

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!