Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which one is better: Loader or Headless Fragments

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!

like image 686
Rahul Rastogi Avatar asked Nov 02 '22 09:11

Rahul Rastogi


1 Answers

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.

like image 55
C B J Avatar answered Nov 10 '22 19:11

C B J