# WindowId.FocusObserver

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

# FocusObserver

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/view/WindowId.FocusObserver "View this page in Java")  

```
abstract class FocusObserver
```

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

Subclass for observing changes to the focus state of an[WindowId](https://developer.android.com/reference/kotlin/android/view/WindowId). You should use the same instance of this class for observing multiple[WindowId](https://developer.android.com/reference/kotlin/android/view/WindowId)objects, since this class is fairly heavy-weight -- the base class includes all of the mechanisms for connecting to and receiving updates from the window.

## Summary

|                                                                 Public constructors                                                                  ||
|---------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [FocusObserver](https://developer.android.com/reference/kotlin/android/view/WindowId.FocusObserver#FocusObserver())`()` Construct a new observer. |

|                                                                                                                                                                                       Public methods                                                                                                                                                                                       ||
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onFocusGained](https://developer.android.com/reference/kotlin/android/view/WindowId.FocusObserver#onFocusGained(android.view.WindowId))`(`token:` `[WindowId](https://developer.android.com/reference/kotlin/android/view/WindowId)!`)` Called when one of the monitored windows gains input focus. |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onFocusLost](https://developer.android.com/reference/kotlin/android/view/WindowId.FocusObserver#onFocusLost(android.view.WindowId))`(`token:` `[WindowId](https://developer.android.com/reference/kotlin/android/view/WindowId)!`)` Called when one of the monitored windows loses input focus.     |

## Public constructors

### FocusObserver

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

```
FocusObserver()
```

Construct a new observer. This observer will be configured so that all of its callbacks are dispatched on the current calling thread.

## Public methods

### onFocusGained

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

```
abstract fun onFocusGained(token: WindowId!): Unit
```

Called when one of the monitored windows gains input focus.  

### onFocusLost

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

```
abstract fun onFocusLost(token: WindowId!): Unit
```

Called when one of the monitored windows loses input focus.