0

from the API it says that one of the loaders characteristics is :

They monitor the source of their data and deliver new results when the content changes.

My question is, how exactly does it do that? can provide me some tutorial or code.. or some kind of explanation ?

user3616866
  • 63
  • 1
  • 1
  • 3

2 Answers2

0

Here is a good answer on SO:

Custom CursorLoader notify data change

Basically you need to register your loader for a callback when the data changed, and then act in it.

I also think this tutorial covers it pretty well:

http://www.androiddesignpatterns.com/2012/08/implementing-loaders.html (Check the 'What Makes Up a Loader?' section)

Community
  • 1
  • 1
Booger
  • 18,579
  • 7
  • 55
  • 72
-1

Yes. I following this tutorial

And the documentation say:

In either case, the given LoaderManager.LoaderCallbacks implementation is associated with the loader, and will be called when the loader state changes. If at the point of this call the caller is in its started state, and the requested loader already exists and has generated its data, then the system calls onLoadFinished() immediately (during initLoader()), so you must be prepared for this to happen. See onLoadFinished for more discussion of this callback

Note that the initLoader() method returns the Loader that is created, but you don't need to capture a reference to it. The LoaderManager manages the life of the loader automatically. The LoaderManager starts and stops loading when necessary, and maintains the state of the loader and its associated content. As this implies, you rarely interact with loaders directly (though for an example of using loader methods to fine-tune a loader's behavior, see the LoaderThrottle sample). You most commonly use the LoaderManager.LoaderCallbacks methods to intervene in the loading process when particular events occur. For more discussion of this topic, see Using the LoaderManager Callbacks.

Lucas Santos
  • 597
  • 6
  • 18