简体   繁体   中英

Empty intent extras in onActivityResult

I have two activities.

First calls second like this:

Intent intent = new Intent(this, Second.class);
startActivityForResult(intent, 1);

returning data in second one:

Intent intent = new Intent();
intent.putExtra("a", "la-la-la");
setResult(RESULT_OK, intent);
finish();

and trying to receive this data in first activity:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

        if ((resultCode == Activity.RESULT_OK) && (currentTask != null)) {
            //Here is empty intent extas!!!

            Log.d("OrderActivity", "RESULT!!");
        }
    }

So, request code and response code returned, but intent extra is empty..??

I also ran into this and found the answer in the comments. To make it more discoverable for the next guy, let's restate as answer:

You must read the same data-type as you put in.

Just call this lines before calling super.onFinish() or wherever you exit the previous activity

Intent intent = getIntent();
intent.putExtra("Date",dateSelected);
setResult(RESULT_OK, intent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM