5
I have a MainActivity
that allows me to open two Fragments
. The class Fragment_1
has a Button
that in his Listener
opens a second activity through the following call:
Intent intent = new Intent(getActivity(), SegundaActivity.class);
getActivity().startActivityForResult(intent, 1);
My problem is that in class Fragment_1
I can’t capture the Intent
response method onActivityResult()
:
if (resultCode == Activity.RESULT_OK && requestCode == 1) {
String resposta = data.getStringExtra("resposta");}
In class SegundaActivity
, the reply is sent as follows::
Intent devolve = new Intent();
devolve.putExtra("resposta", "Resposta");
setResult(Activity.RESULT_OK, devolve);
finish();
Hello ramaral, while waiting for answers I discovered what my problem was: I could not open the Segundaactivity class through the so-called "getActivity(). startActivityForResult(Intent, 1)", ie if I add the method "getActivity()" to the method "startActivityForResult()" I won’t be able to receive the Intent response!! However I will not fail to read what you sent me. Thank you.
– Vitor Mendanha
The links I sent have nothing to do with your question, which is why I deleted the comment.
– ramaral
Okay. However I send the following link that helped me to solve my problem: http://helpdev.com.br/2014/03/31/android-chamando-o-onactivityresult-fragment-onactivityresult-not-called-in-fragment/
– Vitor Mendanha
Is that it? For what I’ve been reading, it’s not enough to call
startActivityForResult(intent, 1)
withoutgetActivity()
. In the Activity that hosts the fragment should be done the overrun of the methodstartActivityForResult()
and callsuper.startActivityForResult()
.– ramaral
Ramaral, with me decided... By the way, when you say override the startActivityForResult() method, didn’t you mean override the onActivityResult() method and call super.onActivityResult()? If so, I already owned it...
– Vitor Mendanha
Yes you’re right: override the method
onActivityResult()
and callsuper.onActivityResult()
– ramaral
Since I was able to find the solution, you could post an answer.
– ramaral
It’s not clear what you’re asking. Please rephrase.
– Paulo Roberto Rosa