I have two activities and a fragment .
Fragment ProfileFragment
is embedded within Activity % with%, that is, when I call ProfileActivity
, it automatically opens this fragment in the center of your screen with two fields: Name and Email.
I need to open this activity ProfileActivity
through my activity ProfileActivity
and return the name and e-mail I typed inside it ).
The big problem is that the return always seeing with MainActivity
, never resultCode == RESULT_CANCELED
.
Follow the code:
-
MainActivity : My main screen where I call
RESULT_OK
- ProfileActivity : My activity which has a fragment inside it, called by XML.
-
ProfileFragment : My fragment with two
ProfileActivity
(Name and Email) that is called byTextView
.
MainActivity ... (code that I call ProfileActivity
):
Intent intent = new Intent(this, ProfileActivity.class);
startActivityForResult(intent, 1);
ProfileFragment ... (code where I feed the return with ProfileActivity.class
in putExtras
):
Intent intent = new Intent();
intent.putExtra("EXTRA_NOME", "Novo nome");
intent.putExtra("EXTRA_EMAIL", "Novo email);
getActivity().setResult(Activity.RESULT_OK, intent);
MainActivity ... (back in my main activity, in the onPause
method)
if (resultCode == RESULT_OK && requestCode == 1) {
mNome = data.getStringExtra("EXTRA_NOME");
mEmail = data.getStringExtra("EXTRA_EMAIL);
}
The problem is that resultCode never comes with onActivityResult
, only RESULT_OK
and my RESULT_CANCELED
always data.getString
. The requestCode is always correct ( 1 ).
Can anyone help me?
Thank you in advance.