android.support.v4.content
Class AsyncTaskLoader<D>

java.lang.Object
  extended by android.support.v4.content.Loader<D>
      extended by android.support.v4.content.AsyncTaskLoader<D>
Direct Known Subclasses:
CursorLoader

public abstract class AsyncTaskLoader<D>
extends Loader<D>

Static library support version of the framework's AsyncTaskLoader. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.


Nested Class Summary
 
Nested classes/interfaces inherited from class android.support.v4.content.Loader
Loader.ForceLoadContentObserver, Loader.OnLoadCompleteListener<D>
 
Constructor Summary
AsyncTaskLoader(android.content.Context context)
           
 
Method Summary
 boolean cancelLoad()
          Attempt to cancel the current load task.
 void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
          Print the Loader's state into the given stream.
abstract  D loadInBackground()
           
 void onCanceled(D data)
          Called if the task was canceled before it was completed.
protected  void onForceLoad()
          Subclasses must implement this to take care of requests to Loader.forceLoad().
protected  D onLoadInBackground()
          Called on a worker thread to perform the actual load.
 void setUpdateThrottle(long delayMS)
          Set amount to throttle updates by.
 void waitForLoader()
          Locks the current thread until the loader completes the current load operation.
 
Methods inherited from class android.support.v4.content.Loader
abandon, dataToString, deliverResult, forceLoad, getContext, getId, isAbandoned, isReset, isStarted, onAbandon, onContentChanged, onReset, onStartLoading, onStopLoading, registerListener, reset, startLoading, stopLoading, takeContentChanged, toString, unregisterListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AsyncTaskLoader

public AsyncTaskLoader(android.content.Context context)
Method Detail

setUpdateThrottle

public void setUpdateThrottle(long delayMS)
Set amount to throttle updates by. This is the minimum time from when the last onLoadInBackground() call has completed until a new load is scheduled.

Parameters:
delayMS - Amount of delay, in milliseconds.

onForceLoad

protected void onForceLoad()
Description copied from class: Loader
Subclasses must implement this to take care of requests to Loader.forceLoad(). This will always be called from the process's main thread.

Overrides:
onForceLoad in class Loader<D>

cancelLoad

public boolean cancelLoad()
Attempt to cancel the current load task. See AsyncTask.cancel(boolean) for more info. Must be called on the main thread of the process.

Cancelling is not an immediate operation, since the load is performed in a background thread. If there is currently a load in progress, this method requests that the load be cancelled, and notes this is the case; once the background thread has completed its work its remaining state will be cleared. If another load request comes in during this time, it will be held until the cancelled load is complete.

Returns:
Returns false if the task could not be cancelled, typically because it has already completed normally, or because Loader.startLoading() hasn't been called; returns true otherwise.

onCanceled

public void onCanceled(D data)
Called if the task was canceled before it was completed. Gives the class a chance to properly dispose of the result.


loadInBackground

public abstract D loadInBackground()

onLoadInBackground

protected D onLoadInBackground()
Called on a worker thread to perform the actual load. Implementations should not deliver the result directly, but should return them from this method, which will eventually end up calling Loader.deliverResult(D) on the UI thread. If implementations need to process the results on the UI thread they may override Loader.deliverResult(D) and do so there.

Returns:
Implementations must return the result of their load operation.

waitForLoader

public void waitForLoader()
Locks the current thread until the loader completes the current load operation. Returns immediately if there is no load operation running. Should not be called from the UI thread: calling it from the UI thread would cause a deadlock.

Use for testing only. Never call this from a UI thread.


dump

public void dump(String prefix,
                 FileDescriptor fd,
                 PrintWriter writer,
                 String[] args)
Description copied from class: Loader
Print the Loader's state into the given stream.

Overrides:
dump in class Loader<D>
Parameters:
prefix - Text to print at the front of each line.
fd - The raw file descriptor that the dump is being sent to.
writer - A PrintWriter to which the dump is to be set.
args - Additional arguments to the dump request.


Copyright © 2013 Marek Kedzierski. All Rights Reserved.