1

This question may sound a little silly and unusual, but pardon me, as I haven't been able to figure out the reason behind the problem. Just a simple case, I start a non UI fragment from onCreate method of an activity, everything works fine. But if I put the same code inside onCreateOptionsMenu callback for the activity, the fragment is not created (Verified it through logs). So, the question arises if there's a certain callback in an activity that I should use to commit fragment transactions.

The code for fragment transactions (try in a sample project) :

    Fragment frag;
    frag = new DownloadFragment();
    FragmentTransaction fr = getFragmentManager().beginTransaction();
    fr.add(frag, "FR");
    fr.commit();

where DownloadFragment is a non UI fragment in which I return null from onCreateView.

Any help would be appreciated, as I have gone through the developer docs for Fragment already.

gaurav jain
  • 3,119
  • 3
  • 31
  • 48
  • what is "non UI fragment"? fragments are meant to be UI components so this sounds like misuse of them. I assume you need Service instead. – kresa Mar 19 '15 at 11:08
  • 1
    Please check : "Adding a fragment without a UI" at this link : http://developer.android.com/guide/components/fragments.html, Also the advantage of such fragments is that they persist state across configuration changes. For this refer this link : http://stackoverflow.com/questions/11531648/what-is-the-use-case-for-a-fragment-with-no-ui. Also, this is just a sample project, and I am not doing anything in the DownloadFragment, so you can call it a little experiment. – gaurav jain Mar 19 '15 at 11:16

0 Answers0