2
I have two activities and a Fragment.
A Fragment ProfileFragment
is embedded within the Activity ProfileActivity
, that is, when I call the Activity ProfileActivity
, 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 MainActivity
and return the name and email I typed inside it (from your Fragment).
The big problem is that the return always seeing with the resultCode == RESULT_CANCELED
, never RESULT_OK
.
Follows the code:
- Mainactivity: My main screen where I call the
ProfileActivity
- Profileactivity: My Activity which has a Fragment within it, called by XML.
- Profilefragment: Man Fragment with two
TextView
(Name and Email) which is called byProfileActivity
.
Mainactivity... (code I call the ProfileActivity.class
):
Intent intent = new Intent(this, ProfileActivity.class);
startActivityForResult(intent, 1);
Profilefragment... (code where food return with putExtras
in the onPause
):
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 method onActivityResult
)
if (resultCode == RESULT_OK && requestCode == 1) {
mNome = data.getStringExtra("EXTRA_NOME");
mEmail = data.getStringExtra("EXTRA_EMAIL);
}
The problem is that the resultCode never comes RESULT_OK
, only RESULT_CANCELED
and my data.getString
at all times NULL
. The requestCode always comes correct (1).
Someone can help me?
Thank you in advance.