I am trying do a simple application for Android
. I have two Activities (A
and B
). In B
I only want select a date
.
I start A
, and do:
Intent intent = new Intent();
intent.setClass(this, B.class);
startActivityForResult(intent,1);
Then, in B
, I do:
Intent intent = getIntent();
setResult(RESULT_OK);
intent.putExtra("Date",dateSelected);
finish();
And, in A
, i have the next method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK && requestCode==1){
Bundle bundle = getIntent().getExtras();
String aux = bundle.getString("nuevo");
.....
}
But data
, and bundle
, are null
. When i debug the code, i see that in class B
, intent
has the Extras
, but then, when i call finish()
and return to class A
, this intent
is not reachable.
How can i solve this problem?
in
A
onActivityResult methodand in
B
try this:
Then, in B, I do:
And, in A:
I know this is answered, but just to give more explanation on the error, you were using
getIntent()
instead of thedata
element received on the callback.getIntent()
returns the Intent that was originally used to open Activity A (maybe when you opened the app or from another activity), anddata
is the intent that Activity B returned as response parameters.Also, you were using
getIntent()
in Activity B instead of creating a new Intent that would be returned to Activity A.Finally, the created intent must be added in
setResult