Let's say I have a simple app consisting of:
A Fragment with a list view to display a list of books
An Activity to hold the fragment
Some web component that will issue a query to a server somewhere to get the list of books to display
What's the best way of wiring these components together? I see a couple of options but which is best (are there any best practices around this)?
Activity issues query to webserver (via AsynTask / new Thread), and pushes results to fragment
Create another fragment without a UI and have this issue the query via AsyncTask / new Thread (like option 1 but will remove the activity being destroyed on screen rotation issues)
Fragment directly calls the webserver, activity does nothing
Add an intent service to do the query and then broadcast results to either:
a) Activity - which pushes them to Fragment
b) Fragment receives broadcasts directly
Are any of these considered a better approach than the other?
Various Fragment related posts have said "consider the fragment a view and the activity the controller" so this would suggest option 3 was maybe not such a good idea.
Option 2 seems a hybrid of considering the activity a controller, kind of delegating some of the 'controller' functionality to another fragment but crucially not the 'view' fragment
Option 4 seems interesting but then you have the issue of having to broadcast all the results (whereas 1 and 2 you will have the actual objects). Granted you could make the broadcasts more efficient (and secure) by using the LocalBroadcastManager but you're still having to broadcast all your web results.
What if I was downloading images (something substantial) rather than (for example) JSON messages that are turned into lightweight Parcelable objects?
As I said, I can think of many ways of doing this - what do we think is the right way?