Loaders example
LouisCAD opened this issue · 2 comments
Hi,
Loaders is the recommended way to make loading on Android data lifecycle aware and avoid reloading it when configuration changes. Could you give an example on how to use a compiled repository in a loader please? Or maybe we can talk on how to make it right here, and I do a pull request for a sample following the discussion?
An example for usage in a retained fragment can also be helpful
Sorry for the late reply on this one. Loaders + Agera doesn't make that much sense, since Agera handles the use-cases differently. As you mention though, using a retained fragment with Agera is the way to achieve this. The testapp is now keeping the data in a retained fragment:
- The repositories are created in
onCreate
- The views are created in
onCreateView
, and associated with the repositories usingUpdatable
s onStart
/onStop
activates/deactivates the repositories.
This keeps the data in the repositories between rotation. A repository is also kept active between rotations, to avoid unnecessary refresh of data (this just happens automatically, no need to do anything to get this behaviour).