# LocusIdCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/LocusIdCompat.java+class:androidx.core.content.LocusIdCompat) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/core#1.5.0)

*** ** * ** ***


```
public final class LocusIdCompat
```

<br />

*** ** * ** ***

An identifier for an unique state (locus) in the application. Should be stable across reboots and backup / restore.

Locus is a new concept introduced on `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#Q` and it lets the intelligence service provided by the Android system correlate state between different subsystems such as content capture, shortcuts, and notifications.

For example, if your app provides an activity representing a chat between 2 users (say `A` and `B`, this chat state could be represented by:

```
LocusIdCompat chatId = new LocusIdCompat("Chat_A_B");
```

And then you should use that `chatId` by:

- Setting it in the chat notification (through `https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder#setLocusId(androidx.core.content.LocusIdCompat)`).
- Setting it into the `https://developer.android.com/reference/androidx/core/content/pm/ShortcutInfoCompat` (through `https://developer.android.com/reference/androidx/core/content/pm/ShortcutInfoCompat.Builder#setLocusId(androidx.core.content.LocusIdCompat)`), if you provide a launcher shortcut for that chat conversation.
- Associating it with the `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureContext.html` of the root view of the chat conversation activity (through `https://developer.android.com/reference/android/view/View.html#getContentCaptureSession()`, then `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureContext.Builder.html` and `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html#setContentCaptureContext(android.view.contentcapture.ContentCaptureContext)` - see `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureManager.html` for more info about content capture).
- Configuring your app to launch the chat conversation through the `https://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW_LOCUS` intent.

NOTE: The LocusId is only used by a on-device intelligence service provided by the Android System, see `https://developer.android.com/reference/android/view/contentcapture/ContentCaptureManager.html` for more details.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/core/content/LocusIdCompat#LocusIdCompat(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html id)` Construct a new LocusIdCompat with the specified id. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/core/content/LocusIdCompat#equals(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html obj)` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/content/LocusIdCompat#getId()()` Gets the canonical `id` associated with the locus. |
| `int` | `https://developer.android.com/reference/androidx/core/content/LocusIdCompat#hashCode()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/LocusId.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 29) https://developer.android.com/reference/androidx/core/content/LocusIdCompat#toLocusId()()` |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/content/LocusIdCompat` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 29) https://developer.android.com/reference/androidx/core/content/LocusIdCompat#toLocusIdCompat(android.content.LocusId)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/LocusId.html locusId)` Returns an instance of LocusIdCompat from given `https://developer.android.com/reference/android/content/LocusId.html`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/content/LocusIdCompat#toString()()` |

## Public constructors

### LocusIdCompat

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

```
public LocusIdCompat(@NonNull String id)
```

Construct a new LocusIdCompat with the specified id.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `id` is empty or `null`. |

## Public methods

### equals

```
public boolean equals(@Nullable Object obj)
```

### getId

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

```
public @NonNull String getId()
```

Gets the canonical `id` associated with the locus.

### hashCode

```
public int hashCode()
```

### toLocusId

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

```
@RequiresApi(value = 29)
public @NonNull LocusId toLocusId()
```

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/LocusId.html` | `https://developer.android.com/reference/android/content/LocusId.html` object from this compat object. |

### toLocusIdCompat

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

```
@RequiresApi(value = 29)
public static @NonNull LocusIdCompat toLocusIdCompat(@NonNull LocusId locusId)
```

Returns an instance of LocusIdCompat from given `https://developer.android.com/reference/android/content/LocusId.html`.

### toString

```
public @NonNull String toString()
```