TransferListener


@UnstableApi
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 functions

Unit
onBytesTransferred(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean,
    bytesTransferred: Int
)

Called incrementally during a transfer.

Unit
onTransferEnd(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean)

Called when a transfer ends.

Unit
onTransferInitializing(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean
)

Called when a transfer is being initialized.

Unit
onTransferStart(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean)

Called when a transfer starts.

Public functions

onBytesTransferred

fun onBytesTransferred(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean,
    bytesTransferred: Int
): Unit

Called incrementally during a transfer.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data being transferred.

isNetwork: Boolean

Whether the data is transferred through a network.

bytesTransferred: Int

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

onTransferEnd

fun onTransferEnd(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean): Unit

Called when a transfer ends.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data being transferred.

isNetwork: Boolean

Whether the data is transferred through a network.

onTransferInitializing

fun onTransferInitializing(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean
): Unit

Called when a transfer is being initialized.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data for which the transfer is initialized.

isNetwork: Boolean

Whether the data is transferred through a network.

onTransferStart

fun onTransferStart(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean): Unit

Called when a transfer starts.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data being transferred.

isNetwork: Boolean

Whether the data is transferred through a network.