0

Please help to understand Activity & Fragment navigation strategy.

For some reasons (need to change app theme / style) I haven't found better way then make few activities with few fragments inside each of them.

So lets assume we have Activities A1 and A2 and fragments connected to them: A1 – F1, F2 and A2 - F3 , F4.

Right now I need to do such queue of openings :

Starting with A1:F1-F2. Then from F2 I would like to start A2 and open F3 on it. Then move to F4. On F4 I would like to make some preferences changes and return back to A1 with remained opened F2.

But F2 should be refreshed to apply preferences changes made by F4.

I've found information about startActivityForResult(...) and processing onActivityResult(...) after it. But onActivityResult(...) is not called at all for my A1. What will be the best for – call onCreateView(...) in F2 when returns back from F4(A2).

So what is the common strategy to work with multiple activities and fragments and how to return results back/force refresh?

Already tried this but without success onActivityResult is not being called in Fragment

EDIT1: code snippets - activity result processing

F2 - fragment:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != Activity.RESULT_OK)
        return;
    makeToast(this.getActivity(), "REPORT OK");
}

A1 - activity:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
}

How I start A2 from F2:

Intent intent = new Intent(getActivity(), DesignerActivity.class); 
startActivityForResult(intent, InputAddressFragment.REQ_CODE_UPADETE_UI);
Community
  • 1
  • 1
Sergii
  • 1,521
  • 3
  • 24
  • 37
  • You can implement this via startActivityForResult() . And your onActivityResult() method for A1 should be called. You sure you have validated your implementation as per http://stackoverflow.com/a/6147919/881771 – Gaurav Feb 25 '14 at 12:18
  • @Gaurav yes, I hoped so, but it just wasn't called. I don't know why. Any possible options here? – Sergii Feb 25 '14 at 12:26
  • Is there any state information within F2 that has to be saved, or do you just want to open A1 with F2 open? – super-qua Feb 25 '14 at 12:31
  • @super-qua I want to redraw F2 after return from F4(A2) as there were some changes in preferences that affect UI – Sergii Feb 25 '14 at 12:34
  • @Sergii - can you post some code snippets. onActivityResult() for both your F2 and A1. i guess somethings wrong there. – Gaurav Feb 25 '14 at 12:40
  • @Gaurav ok , I've edited the question. Possible reason I see now - F2 is DialogFragment, and it was dismissed right after A2 started. But if so why onActivityResult wasn't triggered at not Fragment, but Activity A1 ? – Sergii Feb 25 '14 at 12:50
  • This is because onActivityResult() is first called at activity. Depending on your requirement you can handle it within activity or call super.onActivityResult() to pass it to your fragments. – Gaurav Feb 25 '14 at 12:57
  • @Gaurav called at activity first - sounds strange, debugger shows that activity it wasn't called there. just at fragment – Sergii Feb 25 '14 at 13:07

0 Answers0