# ActionMode.Callback

Artifact: [androidx.appcompat:appcompat](https://developer.android.com/jetpack/androidx/releases/appcompat) [View Source](https://cs.android.com/search?q=file:androidx/appcompat/view/ActionMode.java+class:androidx.appcompat.view.ActionMode.Callback) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

*** ** * ** ***


```
interface ActionMode.Callback
```

<br />

*** ** * ** ***

Callback interface for action modes. Supplied to `https://developer.android.com/reference/kotlin/androidx/appcompat/app/AppCompatDelegate#startSupportActionMode(androidx.appcompat.view.ActionMode.Callback)` (Callback)}, a Callback configures and handles events raised by a user's interaction with an action mode.

An action mode's lifecycle is as follows:

- `https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode.Callback#onCreateActionMode(androidx.appcompat.view.ActionMode,android.view.Menu)` once on initial creation
- `https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode.Callback#onPrepareActionMode(androidx.appcompat.view.ActionMode,android.view.Menu)` after creation and any time the `https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode` is invalidated
- `https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode.Callback#onActionItemClicked(androidx.appcompat.view.ActionMode,android.view.MenuItem)` any time a contextual action button is clicked
- `https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode.Callback#onDestroyActionMode(androidx.appcompat.view.ActionMode)` when the action mode is closed

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode.Callback#onActionItemClicked(androidx.appcompat.view.ActionMode,android.view.MenuItem)(mode: https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode!, item: https://developer.android.com/reference/android/view/MenuItem.html!)` Called to report a user click on an action button. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode.Callback#onCreateActionMode(androidx.appcompat.view.ActionMode,android.view.Menu)(mode: https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode!, menu: https://developer.android.com/reference/android/view/Menu.html!)` Called when action mode is first created. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode.Callback#onDestroyActionMode(androidx.appcompat.view.ActionMode)(mode: https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode!)` Called when an action mode is about to be exited and destroyed. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode.Callback#onPrepareActionMode(androidx.appcompat.view.ActionMode,android.view.Menu)(mode: https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode!, menu: https://developer.android.com/reference/android/view/Menu.html!)` Called to refresh an action mode's action menu whenever it is invalidated. |

## Public functions

### onActionItemClicked

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
fun onActionItemClicked(mode: ActionMode!, item: MenuItem!): Boolean
```

Called to report a user click on an action button.

| Parameters |
|---|---|
| `mode: https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode!` | The current ActionMode |
| `item: https://developer.android.com/reference/android/view/MenuItem.html!` | The item that was clicked |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if this callback handled the event, false if the standard MenuItem invocation should continue. |

### onCreateActionMode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
fun onCreateActionMode(mode: ActionMode!, menu: Menu!): Boolean
```

Called when action mode is first created. The menu supplied will be used to generate action buttons for the action mode.

| Parameters |
|---|---|
| `mode: https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode!` | ActionMode being created |
| `menu: https://developer.android.com/reference/android/view/Menu.html!` | Menu used to populate action buttons |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the action mode should be created, false if entering this mode should be aborted. |

### onDestroyActionMode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
fun onDestroyActionMode(mode: ActionMode!): Unit
```

Called when an action mode is about to be exited and destroyed.

| Parameters |
|---|---|
| `mode: https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode!` | The current ActionMode being destroyed |

### onPrepareActionMode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
fun onPrepareActionMode(mode: ActionMode!, menu: Menu!): Boolean
```

Called to refresh an action mode's action menu whenever it is invalidated.

| Parameters |
|---|---|
| `mode: https://developer.android.com/reference/kotlin/androidx/appcompat/view/ActionMode!` | ActionMode being prepared |
| `menu: https://developer.android.com/reference/android/view/Menu.html!` | Menu used to populate action buttons |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the menu or action mode was updated, false otherwise. |