Can somebody tell my why the Intent data
is always null?
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
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
Posting here as a possible answer though may not be your issue exactly
Ensure your activity returning passes back something like this:
Intent returnIntent = new
returnIntent.putExtra("result", app);
returnIntent.putExtra("element", element);
if (app.getStatus() == 2){
returnIntent.putExtra("update", true);
// Tell the parent that everything went okay
setResult(Activity.RESULT_OK, returnIntent);
Log.i(TAG, "Returning, Result Success");
} else {
// Tell parent that nothing changed
setResult(RESULT_CANCELED, returnIntent);
Log.i(TAG, "Returning, Nothing changed");
}
finish();
I spent a long time suffering from null intents being returned. For me it was because in onBackPressed I was calling super.onBackPressed() before the above code. When I put it after everything worked great. If onStop/onDestroy is called too early the opportunity to pass an intent back is blocked. This may be your issue
You must return some data from the called Activity
to calling Activity
while finishing it.