TransferListener


@UnstableApi
public interface TransferListener

Known direct subclasses
DataSourceContractTest.FakeTransferListener

A TransferListener that only keeps track of the transferred bytes.

DefaultBandwidthMeter

Estimates bandwidth by listening to data transfers.

ExperimentalBandwidthMeter

An experimental BandwidthMeter that estimates bandwidth by listening to data transfers.


A listener of data transfer events.

A transfer usually progresses through multiple steps:

  1. Initializing the underlying resource (e.g. opening a HTTP connection). onTransferInitializing is called before the initialization starts.
  2. Starting the transfer after successfully initializing the resource. onTransferStart is called. Note that this only happens if the initialization was successful.
  3. Transferring data. onBytesTransferred is called frequently during the transfer to indicate progress.
  4. Closing the transfer and the underlying resource. onTransferEnd is called. Note that each onTransferStart will have exactly one corresponding call to onTransferEnd.

Summary

Public methods

abstract void
onBytesTransferred(
    DataSource source,
    DataSpec dataSpec,
    boolean isNetwork,
    int bytesTransferred
)

Called incrementally during a transfer.

abstract void
onTransferEnd(DataSource source, DataSpec dataSpec, boolean isNetwork)

Called when a transfer ends.

abstract void
onTransferInitializing(
    DataSource source,
    DataSpec dataSpec,
    boolean isNetwork
)

Called when a transfer is being initialized.

abstract void
onTransferStart(DataSource source, DataSpec dataSpec, boolean isNetwork)

Called when a transfer starts.

Public methods

onBytesTransferred

abstract void onBytesTransferred(
    DataSource source,
    DataSpec dataSpec,
    boolean isNetwork,
    int bytesTransferred
)

Called incrementally during a transfer.

Parameters
DataSource source

The source performing the transfer.

DataSpec dataSpec

Describes the data being transferred.

boolean isNetwork

Whether the data is transferred through a network.

int bytesTransferred

The number of bytes transferred since the previous call to this method.

onTransferEnd

abstract void onTransferEnd(DataSource source, DataSpec dataSpec, boolean isNetwork)

Called when a transfer ends.

Parameters
DataSource source

The source performing the transfer.

DataSpec dataSpec

Describes the data being transferred.

boolean isNetwork

Whether the data is transferred through a network.

onTransferInitializing

abstract void onTransferInitializing(
    DataSource source,
    DataSpec dataSpec,
    boolean isNetwork
)

Called when a transfer is being initialized.

Parameters
DataSource source

The source performing the transfer.

DataSpec dataSpec

Describes the data for which the transfer is initialized.

boolean isNetwork

Whether the data is transferred through a network.

onTransferStart

abstract void onTransferStart(DataSource source, DataSpec dataSpec, boolean isNetwork)

Called when a transfer starts.

Parameters
DataSource source

The source performing the transfer.

DataSpec dataSpec

Describes the data being transferred.

boolean isNetwork

Whether the data is transferred through a network.