# LocusIdCompat

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/content/LocusIdCompat "View this page in Java")

<br />

```
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[Android Q](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:  

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

And then you should use that`chatId`by:

- Setting it in the chat notification (through[NotificationCompat.Builder.setLocusId(chatId)](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Builder#setLocusId(androidx.core.content.LocusIdCompat))).
- Setting it into the[androidx.core.content.pm.ShortcutInfoCompat](https://developer.android.com/reference/kotlin/androidx/core/content/pm/ShortcutInfoCompat)(through[ShortcutInfoCompat.Builder.setLocusId(chatId)](https://developer.android.com/reference/kotlin/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[android.view.contentcapture.ContentCaptureContext](https://developer.android.com/reference/android/view/contentcapture/ContentCaptureContext.html)of the root view of the chat conversation activity (through[getContentCaptureSession](https://developer.android.com/reference/android/view/View.html#getContentCaptureSession()), then[new ContentCaptureContext.Builder(chatId).build()](https://developer.android.com/reference/android/view/contentcapture/ContentCaptureContext.Builder.html)and[setContentCaptureContext](https://developer.android.com/reference/android/view/contentcapture/ContentCaptureSession.html#setContentCaptureContext(android.view.contentcapture.ContentCaptureContext))- see[android.view.contentcapture.ContentCaptureManager](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[ACTION_VIEW_LOCUS](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[android.view.contentcapture.ContentCaptureManager](https://developer.android.com/reference/android/view/contentcapture/ContentCaptureManager.html)for more details.

## Summary

|                                                                                                                               ### Public constructors                                                                                                                               |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [LocusIdCompat](https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat#LocusIdCompat(java.lang.String))`(id: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Construct a new LocusIdCompat with the specified id. |

|                                               ### Public functions                                                |
|-------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                               | [equals](https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat#equals(java.lang.Object))`(obj: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)`                                                                                                                                                                                                                                                                                |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                 | [getId](https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat#getId())`()` Gets the canonical`id`associated with the locus.                                                                                                                                                                                                                                                                                                                                    |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                       | [hashCode](https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat#hashCode())`()`                                                                                                                                                                                                                                                                                                                                                                               |
| [LocusId](https://developer.android.com/reference/android/content/LocusId.html)                                   | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 29)` [toLocusId](https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat#toLocusId())`()`                                                                                                                                                                                                                                                              |
| `java-static `[LocusIdCompat](https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat) | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 29)` [toLocusIdCompat](https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat#toLocusIdCompat(android.content.LocusId))`(locusId: `[LocusId](https://developer.android.com/reference/android/content/LocusId.html)`)` Returns an instance of LocusIdCompat from given[LocusId](https://developer.android.com/reference/android/content/LocusId.html). |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                 | [toString](https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat#toString())`()`                                                                                                                                                                                                                                                                                                                                                                               |

## Public constructors

### LocusIdCompat

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

```
LocusIdCompat(id: String)
```

Construct a new LocusIdCompat with the specified id.  

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

## Public functions

### equals

```
fun equals(obj: Any?): Boolean
```  

### getId

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

```
fun getId(): String
```

Gets the canonical`id`associated with the locus.  

### hashCode

```
fun hashCode(): Int
```  

### toLocusId

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

```
@RequiresApi(value = 29)
fun toLocusId(): LocusId
```  

|                                     Returns                                     |
|---------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|
| [LocusId](https://developer.android.com/reference/android/content/LocusId.html) | [LocusId](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)
java-static fun toLocusIdCompat(locusId: LocusId): LocusIdCompat
```

Returns an instance of LocusIdCompat from given[LocusId](https://developer.android.com/reference/android/content/LocusId.html).  

### toString

```
fun toString(): String
```