0

I have been reading very much about the nested Fragments onActivityResult issues.

I got the next conclusions.

1) At the Fragment, should call this.startActivityForResult() instead of this.getActivity.startActivityForResult()

2) Overwriting onActivityResult() at the parent Activity calling super.onActivityResult() to propagate the response through fragments.

Until here, the normal way to configure onActivityResult in Fragments.

But I use one implementation of nested fragments. Then I should do some more steps.

3) Here we can see the full process.

enter image description here

First, all my fragments are in root level, doesn't exist another fragment levels.

Then, to try solved the problem, I extend this fix Activity in the main Activity.

CommonActivity

Here, only one difference, I've replaced ActionBarActivity by FragmentActivity.

4)Finally, in the result ListActivity I have the next test code.

Intent output = new Intent();
output.putExtra("pos", position);
this.setResult(Activity.RESULT_OK, output);
this.finish();

THE QUESTION, debbuging, I can see when this.startActivityForResult() is called from Fragment, CommonActivity.startActivityFromFragment(..) is working. But, when response is throw from result ListActivity CommonActivity.onActivityResult(..) never is called.

Why?, Where can be the problem?

Dani
  • 4,001
  • 7
  • 36
  • 60

1 Answers1

0

When called startActivityForResult, results always go to the same Activity from where was called or to Activity the Fragment was attached to(your case), so you can try Override onAttach (Activity activity) - function of Fragment, and see to which Activity was attached the Fragment. Or other way to call startActivityForResult as public function of CommonActivity, so results always will go to CommonActivity.onActivityResult. Good Luck with that!

Taras Okunev
  • 410
  • 6
  • 9
  • Thank you Taras for answer my question, but nothing found. Firstly, in onAttach(Activity) can see that the Activity is right, the Activity which I want it to be. Your second solution I was testing before, but not work neither, onActivityResult never is called. – Dani Oct 31 '14 at 08:03