Can somebody tell my why the Intent data
is always null?
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (requestCode == UPDATE_PROFILE_REQUEST_CODE) { if (data != null) { User user = (User) data.getExtras().getSerializable(USER_DATA_EXTRA); if (user != null) { notifyNeedUpdate(user); } } else { Log.e("Dev", "data is null"); } } }
}
and this is how I set the result:
setResult(RESULT_OK, getIntent().putExtra(ProfileActivity.USER_DATA_EXTRA, constructUser()));
constructUser()
just creates an Object I need.
I always get Log.e("Dev", "data is null");
.
onActivityResult - resultCode is always 0.
onActivityResult is the callback you have on the first activity to grab the contacts you choose. Follow this answer to receive notifications.
The android startActivityForResult method, requires a result from the second activity (activity to be invoked). In such case, we need to override the onActivityResult method that is invoked automatically when second activity returns result.
Make sure that your second activity is not finished before calling
setResult(RESULT_OK, getIntent().putExtra(ProfileActivity.USER_DATA_EXTRA, constructUser()));
i.e. you should call setResult
before onPause
, onStop
, onDestroy
, finish
... etc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With