UrlRequest.Callback
public
static
interface
UrlRequest.Callback
android.net.http.UrlRequest.Callback |
Users of the HTTP stack extend this class to receive callbacks indicating the
progress of a UrlRequest
being processed. An instance of this class
is passed in to UrlRequest.Builder
's constructor when
constructing the UrlRequest
.
Note: All methods will be invoked on the thread of the Executor
used during construction of the UrlRequest
.
Summary
Public methods | |
---|---|
abstract
void
|
onCanceled(UrlRequest request, UrlResponseInfo info)
Invoked if request was canceled via |
abstract
void
|
onFailed(UrlRequest request, UrlResponseInfo info, HttpException error)
Invoked if request failed for any reason after |
abstract
void
|
onReadCompleted(UrlRequest request, UrlResponseInfo info, ByteBuffer byteBuffer)
Invoked whenever part of the response body has been read. |
abstract
void
|
onRedirectReceived(UrlRequest request, UrlResponseInfo info, String newLocationUrl)
Invoked whenever a redirect is encountered. |
abstract
void
|
onResponseStarted(UrlRequest request, UrlResponseInfo info)
Invoked when the final set of headers, after all redirects, is received. |
abstract
void
|
onSucceeded(UrlRequest request, UrlResponseInfo info)
Invoked when request is completed successfully. |
Public methods
onCanceled
public abstract void onCanceled (UrlRequest request, UrlResponseInfo info)
Invoked if request was canceled via UrlRequest.cancel
. Once invoked, no other
Callback
methods will be invoked. Default implementation takes no action.
Parameters | |
---|---|
request |
UrlRequest : Request that was canceled. This is not guaranteed to be the same
object as the one received by other callbacks, nor is it guaranteed to be the one
returned by ERROR(/URLRequest.Builder#build) . However, method calls on
this object will have the same effects as calls on the original
ERROR(/URLRequest) .
This value cannot be null . |
info |
UrlResponseInfo : Response information. May be null if no response was received. |
onFailed
public abstract void onFailed (UrlRequest request, UrlResponseInfo info, HttpException error)
Invoked if request failed for any reason after UrlRequest.start
. Once invoked, no
other Callback
methods will be invoked. error
provides information about
the failure.
Parameters | |
---|---|
request |
UrlRequest : Request that failed. This is not guaranteed to be the same
object as the one received by other callbacks, nor is it guaranteed to be the one
returned by ERROR(/URLRequest.Builder#build) . However, method calls on
this object will have the same effects as calls on the original
ERROR(/URLRequest) .
This value cannot be null . |
info |
UrlResponseInfo : Response information. May be null if no response was received. |
error |
HttpException : information about error.
This value cannot be null . |
onReadCompleted
public abstract void onReadCompleted (UrlRequest request, UrlResponseInfo info, ByteBuffer byteBuffer)
Invoked whenever part of the response body has been read. Only part of the buffer may be
populated, even if the entire response body has not yet been consumed.
With the exception of onCanceled()
, no other Callback
method will be invoked for the request, including onSucceeded()
and onFailed()
, until UrlRequest.read()
is called to attempt to continue reading the response body.
Parameters | |
---|---|
request |
UrlRequest : Request that received data. This is not guaranteed to be the same
object as the one received by other callbacks, nor is it guaranteed to be the one
returned by ERROR(/URLRequest.Builder#build) . However, method calls on
this object will have the same effects as calls on the original
ERROR(/URLRequest) .
This value cannot be null . |
info |
UrlResponseInfo : Response information.
This value cannot be null . |
byteBuffer |
ByteBuffer : The buffer that was passed in to UrlRequest.read() ,
now containing the received data. The buffer's position is updated to the end of the
received data. The buffer's limit is not changed.
This value cannot be null . |
Throws | |
---|---|
Exception |
if an error occurs while processing a read completion. onFailed(UrlRequest, UrlResponseInfo, HttpException)
will be called with the thrown exception set as the cause of the CallbackException . |
onRedirectReceived
public abstract void onRedirectReceived (UrlRequest request, UrlResponseInfo info, String newLocationUrl)
Invoked whenever a redirect is encountered. This will only be invoked between the call to
UrlRequest.start
and onResponseStarted()
. The
body of the redirect response, if it has one, will be ignored.
The redirect will not be followed until the URLRequest's UrlRequest.followRedirect()
method is called, either synchronously or asynchronously.
Parameters | |
---|---|
request |
UrlRequest : Request being redirected. This is not guaranteed to be the same
object as the one received by other callbacks, nor is it guaranteed to be the one
returned by ERROR(/URLRequest.Builder#build) . However, method calls on
this object will have the same effects as calls on the original
ERROR(/URLRequest) .
This value cannot be null . |
info |
UrlResponseInfo : Response information.
This value cannot be null . |
newLocationUrl |
String : Location where request is redirected.
This value cannot be null . |
Throws | |
---|---|
Exception |
if an error occurs while processing a redirect. onFailed(UrlRequest, UrlResponseInfo, HttpException) will
be
called with the thrown exception set as the cause of the CallbackException . |
onResponseStarted
public abstract void onResponseStarted (UrlRequest request, UrlResponseInfo info)
Invoked when the final set of headers, after all redirects, is received. Will only be
invoked once for each request.
With the exception of onCanceled()
, no other Callback
method will be invoked for the request, including onSucceeded()
and onFailed()
, until UrlRequest.read()
is called to attempt to start reading the response body.
Parameters | |
---|---|
request |
UrlRequest : Request that started to get response. This is not guaranteed to be
the same object as the one received by other callbacks, nor is it guaranteed to be
the one returned by ERROR(/URLRequest.Builder#build) . However, method
calls on this object will have the same effects as calls on the original
ERROR(/URLRequest) .
This value cannot be null . |
info |
UrlResponseInfo : Response information.
This value cannot be null . |
Throws | |
---|---|
Exception |
if an error occurs while processing response start. onFailed(UrlRequest, UrlResponseInfo, HttpException)
will
be called with the thrown exception set as the cause of the CallbackException . |
onSucceeded
public abstract void onSucceeded (UrlRequest request, UrlResponseInfo info)
Invoked when request is completed successfully. Once invoked, no other Callback
methods will be invoked.
Parameters | |
---|---|
request |
UrlRequest : Request that succeeded. This is not guaranteed to be the same
object as the one received by other callbacks, nor is it guaranteed to be the one
returned by ERROR(/URLRequest.Builder#build) . However, method calls on
this object will have the same effects as calls on the original
ERROR(/URLRequest) .
This value cannot be null . |
info |
UrlResponseInfo : Response information.
This value cannot be null . |