views:

264

answers:

1

Hi guys.

I am trying to receive data from new Activity to old Activity.

In other words, newer Activity must send intend data to old activity when it finishes.

I've use setResult(resultcode, NewActivity.this.getIntend); on newer activity and

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(data != null) {
        // doing something
    }     
}

on old activity. Receives intend data from newer activity.

But this code doesn't work. Always getting data is null.

How to send intent data from finishing Activity to parent activity ?

Also when create new Activity, I am using following code:

Intent intent = new Intent(Intent.ACTION_PICK);
intent.setClass(OldActivty.this, NewActivity.class);
startActivityForResult(intent, 0);

I don't understand why always getting null intent data from newer one.

how to fix it ?

Please advice.

Thanks,

+1  A: 

As CommonsWare wrote in his comment you are passing the same Intent back to your Activity that you used to start the Activity.

Try something like the following code:

Intent newIntent = new Intent();
newIntent.putExtra(key, yourData)
newIntent.putExtra(key2, moreData)

setResult(resultcode, newIntent);

In your case the Intent is only needed to store the data that is passed back. Therefor you can use the standard constructor.

Janusz