Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Intended use of fragments with services, dialogs etc
    text
    copied!<p>I've been creating android apps for a few months now and I'm having trouble with the intended use of <code>Fragments</code>.</p> <p><code>Fragments</code> are supposed to be reusable UI components but how far do you make them stand alone?</p> <p>One of the <code>Fragments</code> I've created is a <code>ListFragment</code> of downloadable videos. At the moment I've implemented all the methods inside the <code>Fragment</code> with little or none of the methods calling the host <code>Activity</code>. The <code>Fragment</code> calls the <code>Activity</code> for a few minor things but everything like downloading files and finding them on external storage is done by the <code>Fragment</code>.</p> <p>90% of the time I find it's the easiest way of implementing it but there's some times it just doesn't work.</p> <p>An example is a confirmation dialog for deleting a video in my <code>ListFragment</code>. The dialog is a <code>DialogFragment</code> so is attached to the <code>Activity</code> but all the UI update and deletion methods are inside the <code>ListFragment</code>. So I end up with the <code>DialogFragment</code> calling the <code>Activity</code> just to call the <code>ListFragment</code>.</p> <p>Another example is binding to a <code>Service</code>. Do I bind the <code>Activity</code> to the <code>Service</code> or just the <code>Fragment</code>? The <code>Activity</code> has no use for the <code>Service</code> but is a <code>Fragment</code> supposed to be doing all the work of starting and maintaining a <code>Service</code>? If not it means all the <code>Fragments</code> calls to the <code>Service</code> have to go through the <code>Activity</code> so the <code>Fragment</code> is no longer stand alone.</p> <p>I'm wondering if I'm taking the stand alone idea too far, is a <code>Fragment</code> instead supposed to be minimally self-contained and actually rely on the <code>Activity</code> hosting it for all the heavy lifting?</p> <p>Thanks for any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload