michalt38
michalt38

Reputation: 1193

Sending data to a parent activity

how can I send data from chlid activity to a parent activity? I'm using this: In child activity:

Intent intent = new Intent();
intent.putExtra("data", data);
setResult(RESULT_OK);
finish();

And in parent activity:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch(requestCode) {
        case 1:
            if(resultCode == RESULT_OK) {
                    data= (ClientBluetooth)data.getSerializableExtra("data");

   }
}

But i have an error: Attempt to invoke virtual method 'java.io.Serializable android.content.Intent.getSerializableExtra(java.lang.String)' on a null object reference

Upvotes: 1

Views: 44

Answers (1)

Tim
Tim

Reputation: 43314

setResult(RESULT_OK);

You forgot to set the intent, resulting in a null intent in the parent activity. Do this:

setResult(RESULT_OK, intent);

Upvotes: 1

Related Questions