Asynctask解析以及注意事项(四)

2014-11-24 11:01:08 · 作者: · 浏览: 3
rams The parameters of the task.
*
* @return A result, defined by the subclass of this task.
*
* @see #onPreExecute()
* @see #onPostExecute
* @see #publishProgress
*/
// 用户自己实现
protected abstract Result doInBackground(Params... params);
/**
* Runs on the UI thread before {@link #doInBackground}.
*
* @see #onPostExecute
* @see #doInBackground
*/
// 用户自己实现
protected void onPreExecute() {
}
/**
*

Runs on the UI thread after {@link #doInBackground}. The

* specified result is the value returned by {@link #doInBackground}.

*
*

This method won't be invoked if the task was cancelled.

*
* @param result The result of the operation computed by {@link #doInBackground}.
*
* @see #onPreExecute
* @see #doInBackground
* @see #onCancelled(Object)
*/
@SuppressWarnings({"UnusedDeclaration"})
// 用户自己实现
protected void onPostExecute(Result result) {
}
/**
* Runs on the UI thread after {@link #publishProgress} is invoked.
* The specified values are the values passed to {@link #publishProgress}.
*
* @param values The values indicating progress.
*
* @see #publishProgress
* @see #doInBackground
*/
@SuppressWarnings({"UnusedDeclaration"})
// 用户自己实现
protected void onProgressUpdate(Progress... values) {
}
/**
*

Runs on the UI thread after {@link #cancel(boolean)} is invoked and

* {@link #doInBackground(Object[])} has finished.

*
*

The default implementation simply invokes {@link #onCancelled()} and

* ignores the result. If you write your own implementation, do not call
* super.onCancelled(result).

*
* @param result The result, if any, computed in
* {@link #doInBackground(Object[])}, can be null
*
* @see #cancel(boolean)
* @see #isCancelled()
*/
@SuppressWarnings({"UnusedParameters"})
protected void onCancelled(Result result) {
onCancelled();
}
/**
*

Applications should preferably override {@link #onCancelled(Object)}.

* This method is invoked by the default implementation of
* {@link #onCancelled(Object)}.

*
*

Runs on the UI thread after {@link #cancel(boolean)} is invoked and

* {@link #doInBackground(Object[])} has finished.

*
* @see #onCancelled(Object)
* @see #cancel(boolean)
* @see #isCancelled()
*/
protected void onCancelled() {
}
/**
* Returns true if this task was cancelled before it completed
* normally. If you are calling {@link #cancel(boolean)} on the task,
* the value returned by this method should be checked periodically from
* {@link #doInBackground(Object[])} to end the task as soon as possible.
*
* @return true if task was cancelled before it completed
*
* @see #cancel(boolean)
*/
public final boolean isCancelled() {
return mCancelled.get();
}
/**
*

Attempts to cancel execution of this task. This attempt will

* fail if the task has already completed, already been cancelled,