# SocketKeepalive.Callback

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Callback

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/net/SocketKeepalive.Callback "View this page in Java")  

```
open class Callback
```

|---|------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                               ||
| ↳ | [android.net.SocketKeepalive.Callback](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive.Callback#) |

The callback which app can use to learn the status changes of[SocketKeepalive](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive). See[SocketKeepalive](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive).

## Summary

|                                                   Public constructors                                                    ||
|-----------------------------------------------------------------------------------------------------------------------|---|
| [Callback](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive.Callback#Callback())`()` <br /> |

|                                                                                                                                                  Public methods                                                                                                                                                  ||
|----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onDataReceived](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive.Callback#onDataReceived())`()` The keepalive on a TCP socket was stopped because the socket received data.                         |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onError](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive.Callback#onError(kotlin.Int))`(`error:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` An error occurred. |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onStarted](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive.Callback#onStarted())`()` The requested keepalive was successfully started.                                                             |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onStopped](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive.Callback#onStopped())`()` The keepalive was successfully stopped.                                                                       |

## Public constructors

### Callback

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Callback()
```

## Public methods

### onDataReceived

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onDataReceived(): Unit
```

The keepalive on a TCP socket was stopped because the socket received data. This is never called for UDP sockets.  

### onError

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onError(error: Int): Unit
```

An error occurred.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ||
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `error` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Value is[android.net.SocketKeepalive#ERROR_INVALID_NETWORK](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive#ERROR_INVALID_NETWORK:kotlin.Int),[android.net.SocketKeepalive#ERROR_INVALID_IP_ADDRESS](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive#ERROR_INVALID_IP_ADDRESS:kotlin.Int),[android.net.SocketKeepalive#ERROR_INVALID_PORT](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive#ERROR_INVALID_PORT:kotlin.Int),[android.net.SocketKeepalive#ERROR_INVALID_LENGTH](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive#ERROR_INVALID_LENGTH:kotlin.Int),[android.net.SocketKeepalive#ERROR_INVALID_INTERVAL](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive#ERROR_INVALID_INTERVAL:kotlin.Int),[android.net.SocketKeepalive#ERROR_INVALID_SOCKET](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive#ERROR_INVALID_SOCKET:kotlin.Int),[android.net.SocketKeepalive#ERROR_SOCKET_NOT_IDLE](https://developer.android.com/reference/kotlin/android/net/SocketKeepalive#ERROR_SOCKET_NOT_IDLE:kotlin.Int), or android.net.SocketKeepalive.ERROR_NO_SUCH_SLOT |

### onStarted

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onStarted(): Unit
```

The requested keepalive was successfully started.  

### onStopped

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onStopped(): Unit
```

The keepalive was successfully stopped.