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

# UiTranslationStateCallback

*** ** * ** ***

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


`
public


interface
UiTranslationStateCallback
`


`


`

|---|
| android.view.translation.UiTranslationStateCallback |

<br />

*** ** * ** ***

Callback for listening to UI Translation state changes. See `https://developer.android.com/reference/android/view/translation/UiTranslationManager#registerUiTranslationStateCallback(java.util.concurrent.Executor,%20android.view.translation.UiTranslationStateCallback)`.


Prior to Android version `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU`:

- Callback methods *without* `packageName` are invoked. Apps with minSdkVersion lower than `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU` *must* implement those methods if they want to handle the events.
- Callback methods for a particular event *may* be called multiple times consecutively, even when the translation state has not changed (e.g., `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onStarted(android.icu.util.ULocale,%20android.icu.util.ULocale,%20java.lang.String)` may be called multiple times even after translation has already started).


In Android version `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU` and later:

- If both methods with and without `packageName` are implemented (e.g., `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onFinished()` and `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onFinished(java.lang.String)`, only the one *with* `packageName` will be called.
- Callback methods for a particular event will *not* be called multiple times consecutively. They will only be called when the translation state has actually changed (e.g., from "started" to "paused"). Note: "resumed" is not considered a separate state from "started", so `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onResumed(android.icu.util.ULocale,%20android.icu.util.ULocale,%20java.lang.String)` will never be called after `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onStarted(android.icu.util.ULocale,%20android.icu.util.ULocale,%20java.lang.String)`.\<

<br />

## Summary

| ### Public methods ||
|---|---|
| ` default void` | ` https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onFinished(java.lang.String)(https://developer.android.com/reference/java/lang/String packageName) ` The UI Translation session has ended. |
| ` abstract void` | ` https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onFinished()() ` The UI Translation session has ended. |
| ` abstract void` | ` https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onPaused()() ` The system is requesting that the application temporarily show the UI contents in their original language. |
| ` default void` | ` https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onPaused(java.lang.String)(https://developer.android.com/reference/java/lang/String packageName) ` The system is requesting that the application temporarily show the UI contents in their original language. |
| ` default void` | ` https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onResumed(android.icu.util.ULocale,%20android.icu.util.ULocale,%20java.lang.String)(https://developer.android.com/reference/android/icu/util/ULocale sourceLocale, https://developer.android.com/reference/android/icu/util/ULocale targetLocale, https://developer.android.com/reference/java/lang/String packageName) ` The system is requesting that the application restore from the temporarily paused state and show the content in the translated language. |
| ` default void` | ` https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onResumed(android.icu.util.ULocale,%20android.icu.util.ULocale)(https://developer.android.com/reference/android/icu/util/ULocale sourceLocale, https://developer.android.com/reference/android/icu/util/ULocale targetLocale) ` The system is requesting that the application restore from the temporarily paused state and show the content in the translated language. |
| ` default void` | ` https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onStarted(android.icu.util.ULocale,%20android.icu.util.ULocale)(https://developer.android.com/reference/android/icu/util/ULocale sourceLocale, https://developer.android.com/reference/android/icu/util/ULocale targetLocale) ` The system is requesting translation of the UI from `sourceLocale` to `targetLocale`. |
| ` default void` | ` https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onStarted(android.icu.util.ULocale,%20android.icu.util.ULocale,%20java.lang.String)(https://developer.android.com/reference/android/icu/util/ULocale sourceLocale, https://developer.android.com/reference/android/icu/util/ULocale targetLocale, https://developer.android.com/reference/java/lang/String packageName) ` The system is requesting translation of the UI from `sourceLocale` to `targetLocale`. |

## Public methods

### onFinished

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

```
public void onFinished (String packageName)
```

The UI Translation session has ended.


Apps *may* implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onFinished()` instead if they don't need the name of the
package that owns the activity being translated.


Apps with minSdkVersion lower than `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU`
*must* implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onFinished()` if they want to handle the "finished" event.

<br />

| Parameters ||
|---|---|
| `packageName` | `String`: The name of the package that owns the activity being translated. This value cannot be `null`. <br /> |

### onFinished

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

```
public abstract void onFinished ()
```

The UI Translation session has ended.


Apps should implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onFinished(java.lang.String)` as well if they need the name of the
package that owns the activity being translated.

<br />

### onPaused

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

```
public abstract void onPaused ()
```

The system is requesting that the application temporarily show the UI contents in their
original language.


Apps should implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onPaused(java.lang.String)` as well if they need the name of the
package that owns the activity being translated.

<br />

### onPaused

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

```
public void onPaused (String packageName)
```

The system is requesting that the application temporarily show the UI contents in their
original language.


Apps *may* implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onPaused()` instead if they don't need the name of the
package that owns the activity being translated.


Apps with minSdkVersion lower than `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU`
*must* implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onPaused()` if they want to handle the "paused" event.

<br />

| Parameters ||
|---|---|
| `packageName` | `String`: This value cannot be `null`. <br /> |

### onResumed

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

```
public void onResumed (ULocale sourceLocale, 
                ULocale targetLocale, 
                String packageName)
```

The system is requesting that the application restore from the temporarily paused state and
show the content in the translated language.


Apps *may* implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onResumed(android.icu.util.ULocale,%20android.icu.util.ULocale)` instead if they don't need
the name of the package that owns the activity being translated.


Apps with minSdkVersion lower than `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU`
*must* implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onResumed(android.icu.util.ULocale,%20android.icu.util.ULocale)` if they want to handle the
"resumed" event.

<br />

| Parameters ||
|---|---|
| `sourceLocale` | `ULocale`: `https://developer.android.com/reference/android/icu/util/ULocale` the UI is being translated from. This value cannot be `null`. <br /> |
| `targetLocale` | `ULocale`: `https://developer.android.com/reference/android/icu/util/ULocale` the UI is being translated to. This value cannot be `null`. <br /> |
| `packageName` | `String`: The name of the package that owns the activity being translated. This value cannot be `null`. <br /> |

### onResumed

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

```
public void onResumed (ULocale sourceLocale, 
                ULocale targetLocale)
```

The system is requesting that the application restore from the temporarily paused state and
show the content in the translated language.


Apps should implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onResumed(android.icu.util.ULocale,%20android.icu.util.ULocale,%20java.lang.String)` instead if they need the
name of the package that owns the activity being translated.


Apps with minSdkVersion lower than `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU`
*must* implement this method if they want to handle the "resumed" event.

<br />

| Parameters ||
|---|---|
| `sourceLocale` | `ULocale`: `https://developer.android.com/reference/android/icu/util/ULocale` the UI is being translated from. This value cannot be `null`. <br /> |
| `targetLocale` | `ULocale`: `https://developer.android.com/reference/android/icu/util/ULocale` the UI is being translated to. This value cannot be `null`. <br /> |

### onStarted

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

```
public void onStarted (ULocale sourceLocale, 
                ULocale targetLocale)
```

The system is requesting translation of the UI from `sourceLocale` to `targetLocale`.


This is also called if either the requested `sourceLocale` or `targetLocale` has
changed.


Apps should implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onStarted(android.icu.util.ULocale,%20android.icu.util.ULocale,%20java.lang.String)` instead if they need the
name of the package that owns the activity being translated.


Apps with minSdkVersion lower than `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU`
*must* implement this method if they want to handle the "started" event.

<br />

| Parameters ||
|---|---|
| `sourceLocale` | `ULocale`: `https://developer.android.com/reference/android/icu/util/ULocale` the UI is being translated from. This value cannot be `null`. <br /> |
| `targetLocale` | `ULocale`: `https://developer.android.com/reference/android/icu/util/ULocale` the UI is being translated to. This value cannot be `null`. <br /> |

### onStarted

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

```
public void onStarted (ULocale sourceLocale, 
                ULocale targetLocale, 
                String packageName)
```

The system is requesting translation of the UI from `sourceLocale` to `targetLocale`.


This is also called if either the requested `sourceLocale` or `targetLocale` has
changed.


Apps *may* implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onStarted(android.icu.util.ULocale,%20android.icu.util.ULocale)` instead if they don't need
the name of the package that owns the activity being translated.


Apps with minSdkVersion lower than `https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU`
*must* implement `https://developer.android.com/reference/android/view/translation/UiTranslationStateCallback#onStarted(android.icu.util.ULocale,%20android.icu.util.ULocale)` if they want to handle the
"started" event.

<br />

| Parameters ||
|---|---|
| `sourceLocale` | `ULocale`: `https://developer.android.com/reference/android/icu/util/ULocale` the UI is being translated from. This value cannot be `null`. <br /> |
| `targetLocale` | `ULocale`: `https://developer.android.com/reference/android/icu/util/ULocale` the UI is being translated to. This value cannot be `null`. <br /> |
| `packageName` | `String`: The name of the package that owns the activity being translated. This value cannot be `null`. <br /> |