# PlatformThreadContextElement

Artifact: [androidx.tracing:tracing](https://developer.android.com/jetpack/androidx/releases/tracing) [View Source](https://cs.android.com/search?q=file:androidx/tracing/ContextElements.kt+class:androidx.tracing.PlatformThreadContextElement) Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

*** ** * ** ***


```
public abstract class PlatformThreadContextElement extends AbstractCoroutineContextElement implements PropagationToken, AutoCloseable
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [kotlin.coroutines.AbstractCoroutineContextElement](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-abstract-coroutine-context-element/index.html) ||
|   | ↳ | [androidx.tracing.PlatformThreadContextElement](https://developer.android.com/reference/androidx/tracing/PlatformThreadContextElement) |

*** ** * ** ***

We use the `https://developer.android.com/reference/androidx/tracing/PlatformThreadContextElement` construct to know when a coroutine has suspended, and about to resume on a `Thread`.

## Summary

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/tracing/PlatformThreadContextElement#close()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html` | `@https://developer.android.com/reference/androidx/tracing/DelicateTracingApi https://developer.android.com/reference/androidx/tracing/PlatformThreadContextElement#contextElementOrNull()()` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/tracing/PlatformThreadContextElement#getCategory()()` The `category` that a trace section belongs to. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Long.html>` | `https://developer.android.com/reference/androidx/tracing/PlatformThreadContextElement#getFlowIds()()` The underlying Perfetto flow ids that can be used to determine the causality for a given trace section. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/tracing/PlatformThreadContextElement#getName()()` The `name` of the code section as it appears in a trace. |
| `void` | `https://developer.android.com/reference/androidx/tracing/PlatformThreadContextElement#setCategory(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html value)` The `category` that a trace section belongs to. |
| `void` | `https://developer.android.com/reference/androidx/tracing/PlatformThreadContextElement#setName(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html value)` The `name` of the code section as it appears in a trace. |

### Inherited methods

From [kotlin.coroutines.AbstractCoroutineContextElement](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-abstract-coroutine-context-element/index.html) `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-key/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-abstract-coroutine-context-element/get-key.html()` From [kotlin.coroutines.CoroutineContext](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html) `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/plus.html(@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html context)` From [kotlin.coroutines.CoroutineContext.Element](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html) `@https://developer.android.com/reference/androidx/annotation/NonNull R` `<R extends https://developer.android.com/reference/java/lang/Object.html> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/fold.html(
@https://developer.android.com/reference/androidx/annotation/NonNull R initial,
@https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull R, @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html, @https://developer.android.com/reference/androidx/annotation/NonNull R> operation
)` `E` `<E extends https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/get.html(
@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-key/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull E> key
)` `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/minus-key.html(@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-key/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> key)`

## Public methods

### close

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

```
public void close()
```

### contextElementOrNull

```
@DelicateTracingApi
public CoroutineContext.Element contextElementOrNull()
```

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html` | a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html` that needs to be installed in the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/index.html` prior to dispatching the suspending block of code being traced; if the token is being used in a suspending context. |

### getCategory

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

```
public @NonNull String getCategory()
```

The `category` that a trace section belongs to.

### getFlowIds

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

```
public @NonNull List<@NonNull Long> getFlowIds()
```

The underlying Perfetto flow ids that can be used to determine the causality for a given trace section.

### getName

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

```
public @NonNull String getName()
```

The `name` of the code section as it appears in a trace.

### setCategory

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

```
public void setCategory(@NonNull String value)
```

The `category` that a trace section belongs to.

### setName

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

```
public void setName(@NonNull String value)
```

The `name` of the code section as it appears in a trace.