Getting familiar with Loaders - Part 2

This is part 2 of Loaders article series

A loader has 6 states maintianed by fields in Loader class.

    boolean mStarted = false;
    boolean mAbandoned = false;
    boolean mReset = true;
    boolean mContentChanged = false;
    boolean mProcessingChange = false;

Reset

A loader starts in reset state. This flag will also become true if reset method is invoked on Loader, after that onReset() method is called. In onReset you should clean any resources attached to loader.

This state can be queried using isReset() method.

Started

A loader is in started state if startLoading is invoked on it. startLoading() sets mStarted to true and calls onStartLoading() in Loader. In this state, you should start loading data, if data is cached you can deliver it immidiately.

You should call forceLoade() from this method, if it is invoked for the first time.

This state can be queried using isStarted() method.

Stopped

Loader goes into sotpped state if stopLoading() is called by Loder. In this state, loader should not deliver new results, rather it should cache the result and deliver them on next restart.

You should free any resources related to Loader in this state.

ContentChanged

This flag notifies the loader that content is changed. You can check this flag in onStartLoading to see if something has changed while Loader was stopped. When Loader detects this flag onContentChanged is called on Loader to handle the change.

Default implementation of onContentChanged() calls forceload() if loader is started.

Abandoned and ProcessingChange

I haven’t used these states yet, I will update it once I use these somewhere.

Flow Chart

comming soon

top