which one is better: Loader or Headless Fragments

688 views Asked by At

Since, there has always been some issues with AsyncTask. So, now, i am thinking about to move to either Loader or Headless Fragments.

My app is a social media app, where people comment, post, likes and do much more things.. Each Activity fetches images from server, and I have to cache them. To handle the runtime configuration changes which one would be better for this app. Loader or Headless Fragments.

I am to handle each pitfall like when the data is being loaded from server and activity goes in onStop() or onPause() state. Help!

1

There are 1 answers

0
C B J On

Loaders work well but require a bit of "boilerplate" (repeating code) and are a bit messy in my opinion. A gotcha with loaders is that the loader ID must be unique in an activity or they will not behave as expected (fail to start/don't return results etc).. normally a trivial issue unless the loaders are in fragments and you have multiple fragments in your activity (tip: use id resources). I haven't used headless fragments as a substitute for loaders yet, but I have been told (but not confirmed) that they are now the Google "best practice" in preference to loaders. It does seem to be a potentially cleaner solution, in my opinion.. look at using headless fragments first.

Hope that helps, good luck.

CJ.