Methods Summary |
---|
public void | abandon()Tell the Loader that it is being abandoned. This is called prior
to {@link #reset} to have it retain its current data but not report
any new data.
mAbandoned = true;
onAbandon();
|
public void | commitContentChanged()Commit that you have actually fully processed a content change that
was returned by {@link #takeContentChanged}. This is for use with
{@link #rollbackContentChanged()} to handle situations where a load
is cancelled. Call this when you have completely processed a load
without it being cancelled.
mProcessingChange = false;
|
public java.lang.String | dataToString(D data)For debugging, converts an instance of the Loader's data class to
a string that can be printed. Must handle a null data.
StringBuilder sb = new StringBuilder(64);
DebugUtils.buildShortClassTag(data, sb);
sb.append("}");
return sb.toString();
|
public void | deliverResult(D data)Sends the result of the load to the registered listener. Should only be called by subclasses.
Must be called from the process's main thread.
if (mListener != null) {
mListener.onLoadComplete(this, data);
}
|
public void | dump(java.lang.String prefix, java.io.FileDescriptor fd, java.io.PrintWriter writer, java.lang.String[] args)Print the Loader's state into the given stream.
writer.print(prefix); writer.print("mId="); writer.print(mId);
writer.print(" mListener="); writer.println(mListener);
if (mStarted || mContentChanged || mProcessingChange) {
writer.print(prefix); writer.print("mStarted="); writer.print(mStarted);
writer.print(" mContentChanged="); writer.print(mContentChanged);
writer.print(" mProcessingChange="); writer.println(mProcessingChange);
}
if (mAbandoned || mReset) {
writer.print(prefix); writer.print("mAbandoned="); writer.print(mAbandoned);
writer.print(" mReset="); writer.println(mReset);
}
|
public void | forceLoad()Force an asynchronous load. Unlike {@link #startLoading()} this will ignore a previously
loaded data set and load a new one. This simply calls through to the
implementation's {@link #onForceLoad()}. You generally should only call this
when the loader is started -- that is, {@link #isStarted()} returns true.
Must be called from the process's main thread.
onForceLoad();
|
public android.content.Context | getContext()
return mContext;
|
public int | getId()
return mId;
|
public boolean | isAbandoned()Return whether this loader has been abandoned. In this state, the
loader must not report any new data, and must keep
its last reported data valid until it is finally reset.
return mAbandoned;
|
public boolean | isReset()Return whether this load has been reset. That is, either the loader
has not yet been started for the first time, or its {@link #reset()}
has been called.
return mReset;
|
public boolean | isStarted()Return whether this load has been started. That is, its {@link #startLoading()}
has been called and no calls to {@link #stopLoading()} or
{@link #reset()} have yet been made.
return mStarted;
|
protected void | onAbandon()Subclasses implement this to take care of being abandoned. This is
an optional intermediate state prior to {@link #onReset()} -- it means that
the client is no longer interested in any new data from the loader,
so the loader must not report any further updates. However, the
loader must keep its last reported data valid until the final
{@link #onReset()} happens. You can retrieve the current abandoned
state with {@link #isAbandoned}.
|
public void | onContentChanged()Called when {@link ForceLoadContentObserver} detects a change. The
default implementation checks to see if the loader is currently started;
if so, it simply calls {@link #forceLoad()}; otherwise, it sets a flag
so that {@link #takeContentChanged()} returns true.
Must be called from the process's main thread.
if (mStarted) {
forceLoad();
} else {
// This loader has been stopped, so we don't want to load
// new data right now... but keep track of it changing to
// refresh later if we start again.
mContentChanged = true;
}
|
protected void | onForceLoad()Subclasses must implement this to take care of requests to {@link #forceLoad()}.
This will always be called from the process's main thread.
|
protected void | onReset()Subclasses must implement this to take care of resetting their loader,
as per {@link #reset()}. This is not called by clients directly,
but as a result of a call to {@link #reset()}.
This will always be called from the process's main thread.
|
protected void | onStartLoading()Subclasses must implement this to take care of loading their data,
as per {@link #startLoading()}. This is not called by clients directly,
but as a result of a call to {@link #startLoading()}.
|
protected void | onStopLoading()Subclasses must implement this to take care of stopping their loader,
as per {@link #stopLoading()}. This is not called by clients directly,
but as a result of a call to {@link #stopLoading()}.
This will always be called from the process's main thread.
|
public void | registerListener(int id, android.support.v4.content.Loader$OnLoadCompleteListener listener)Registers a class that will receive callbacks when a load is complete.
The callback will be called on the process's main thread so it's safe to
pass the results to widgets.
Must be called from the process's main thread.
if (mListener != null) {
throw new IllegalStateException("There is already a listener registered");
}
mListener = listener;
mId = id;
|
public void | reset()Resets the state of the Loader. The Loader should at this point free
all of its resources, since it may never be called again; however, its
{@link #startLoading()} may later be called at which point it must be
able to start running again.
This updates the Loader's internal state so that
{@link #isStarted()} and {@link #isReset()} will return the correct
values, and then calls the implementation's {@link #onReset()}.
Must be called from the process's main thread.
onReset();
mReset = true;
mStarted = false;
mAbandoned = false;
mContentChanged = false;
mProcessingChange = false;
|
public void | rollbackContentChanged()Report that you have abandoned the processing of a content change that
was returned by {@link #takeContentChanged()} and would like to rollback
to the state where there is again a pending content change. This is
to handle the case where a data load due to a content change has been
canceled before its data was delivered back to the loader.
if (mProcessingChange) {
mContentChanged = true;
}
|
public final void | startLoading()Starts an asynchronous load of the Loader's data. When the result
is ready the callbacks will be called on the process's main thread.
If a previous load has been completed and is still valid
the result may be passed to the callbacks immediately.
The loader will monitor the source of
the data set and may deliver future callbacks if the source changes.
Calling {@link #stopLoading} will stop the delivery of callbacks.
This updates the Loader's internal state so that
{@link #isStarted()} and {@link #isReset()} will return the correct
values, and then calls the implementation's {@link #onStartLoading()}.
Must be called from the process's main thread.
mStarted = true;
mReset = false;
mAbandoned = false;
onStartLoading();
|
public void | stopLoading()Stops delivery of updates until the next time {@link #startLoading()} is called.
Implementations should not invalidate their data at this point --
clients are still free to use the last data the loader reported. They will,
however, typically stop reporting new data if the data changes; they can
still monitor for changes, but must not report them to the client until and
if {@link #startLoading()} is later called.
This updates the Loader's internal state so that
{@link #isStarted()} will return the correct
value, and then calls the implementation's {@link #onStopLoading()}.
Must be called from the process's main thread.
mStarted = false;
onStopLoading();
|
public boolean | takeContentChanged()Take the current flag indicating whether the loader's content had
changed while it was stopped. If it had, true is returned and the
flag is cleared.
boolean res = mContentChanged;
mContentChanged = false;
mProcessingChange |= res;
return res;
|
public java.lang.String | toString()
StringBuilder sb = new StringBuilder(64);
DebugUtils.buildShortClassTag(this, sb);
sb.append(" id=");
sb.append(mId);
sb.append("}");
return sb.toString();
|
public void | unregisterListener(android.support.v4.content.Loader$OnLoadCompleteListener listener)Remove a listener that was previously added with {@link #registerListener}.
Must be called from the process's main thread.
if (mListener == null) {
throw new IllegalStateException("No listener register");
}
if (mListener != listener) {
throw new IllegalArgumentException("Attempting to unregister the wrong listener");
}
mListener = null;
|