# OngoingActivity.Builder

Artifact: [androidx.wear:wear-ongoing](https://developer.android.com/jetpack/androidx/releases/wear) [View Source](https://cs.android.com/search?q=file:androidx/wear/ongoing/OngoingActivity.java+class:androidx.wear.ongoing.OngoingActivity.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear#1.0.0)

*** ** * ** ***


```
public final class OngoingActivity.Builder
```

<br />

*** ** * ** ***

Builder used to build an `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`

Note that many fields take a default value from the provided notification if not explicitly set. If set explicitly and in the notification, the value set through the `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` will be used.

The only required fields (set through the builder or the notification) are static icon and pending intent.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#Builder(android.content.Context,int,androidx.core.app.NotificationCompat.Builder)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, int notificationId, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder notificationBuilder )` Construct a new empty `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder`, associated with the given notification. |
| `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#Builder(android.content.Context,java.lang.String,int,androidx.core.app.NotificationCompat.Builder)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html tag, int notificationId, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder notificationBuilder )` Construct a new empty `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder`, associated with the given notification. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#build()()` Combine all options provided and the information in the notification if needed, return a new `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` object. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setAnimatedIcon(android.graphics.drawable.Icon)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Icon.html animatedIcon)` Set the animated icon that can be used on some surfaces to represent this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setAnimatedIcon(int)(@https://developer.android.com/reference/androidx/annotation/DrawableRes int animatedIcon)` Set the animated icon that can be used on some surfaces to represent this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setCategory(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html category)` Set the category of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setContentDescription(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html contentDescription)` Sets the content description of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setLocusId(androidx.core.content.LocusIdCompat)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/content/LocusIdCompat locusId)` Set the corresponding LocusId of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, this will be used by the launcher to identify the corresponding launcher item and display it accordingly. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setOngoingActivityId(int)(int ongoingActivityId)` Give an id to this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, as a way to reference it in `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#recoverOngoingActivity(android.content.Context,int)` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setStaticIcon(android.graphics.drawable.Icon)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/drawable/Icon.html staticIcon)` Set the static icon that can be used on some surfaces to represent this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, for example in the WatchFace in ambient mode. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setStaticIcon(int)(@https://developer.android.com/reference/androidx/annotation/DrawableRes int staticIcon)` Set the static icon that can be used on some surfaces to represent this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, for example in the WatchFace in ambient mode. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setStatus(androidx.wear.ongoing.Status)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/Status status)` Set the initial status of this ongoing activity, the status may be displayed on the UI to show progress of the Ongoing Activity. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setTitle(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html title)` Sets the Title of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setTouchIntent(android.app.PendingIntent)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/PendingIntent.html touchIntent)` Set the intent to be used to go back to the activity when the user interacts with the Ongoing Activity in other surfaces (for example, taps the Icon on the WatchFace). |

## Public constructors

### Builder

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

```
public Builder(
    @NonNull Context context,
    int notificationId,
    @NonNull NotificationCompat.Builder notificationBuilder
)
```

Construct a new empty `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder`, associated with the given notification.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | to be used during the life of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder`, will NOT pass a reference into the built `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` |
| `int notificationId` | id that will be used to post the notification associated with this Ongoing Activity |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder notificationBuilder` | builder for the notification associated with this Ongoing Activity |

### Builder

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

```
public Builder(
    @NonNull Context context,
    @NonNull String tag,
    int notificationId,
    @NonNull NotificationCompat.Builder notificationBuilder
)
```

Construct a new empty `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder`, associated with the given notification.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | to be used during the life of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder`, will NOT pass a reference into the built `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html tag` | tag that will be used to post the notification associated with this Ongoing Activity |
| `int notificationId` | id that will be used to post the notification associated with this Ongoing Activity |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder notificationBuilder` | builder for the notification associated with this Ongoing Activity |

## Public methods

### build

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

```
public @NonNull OngoingActivity build()
```

Combine all options provided and the information in the notification if needed, return a new `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` object. See particular setters for information on what defaults from the notification are used.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the static icon or the touch intent are not provided. |

### setAnimatedIcon

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

```
public @NonNull OngoingActivity.Builder setAnimatedIcon(@Nullable Icon animatedIcon)
```

Set the animated icon that can be used on some surfaces to represent this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. For example, in the WatchFace. Should be white with a transparent background, preferably an AnimatedVectorDrawable.

If not provided, or set to null, the static icon will be used.

### setAnimatedIcon

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

```
public @NonNull OngoingActivity.Builder setAnimatedIcon(@DrawableRes int animatedIcon)
```

Set the animated icon that can be used on some surfaces to represent this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. For example, in the WatchFace. Should be white with a transparent background, preferably an AnimatedVectorDrawable.

If not provided, the static icon will be used.

### setCategory

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

```
public @NonNull OngoingActivity.Builder setCategory(@Nullable String category)
```

Set the category of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. It may be used by the system to prioritize displaying the `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`.

If set, it Must be one of the predefined notification categories (see the `CATEGORY_*` constants in `https://developer.android.com/reference/androidx/core/app/NotificationCompat`) that best describes this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`.

If this is not set (or null), the notification's category is used if present.

### setContentDescription

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

```
public @NonNull OngoingActivity.Builder setContentDescription(@Nullable String contentDescription)
```

Sets the content description of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. If this is set to a non-null value, it could be used by accesibility services to describe the ongoing activity.

No defaults from the notification are used for this field.

### setLocusId

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

```
public @NonNull OngoingActivity.Builder setLocusId(@Nullable LocusIdCompat locusId)
```

Set the corresponding LocusId of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, this will be used by the launcher to identify the corresponding launcher item and display it accordingly.

If set to null or not set, the launcher will use heuristics to do the matching.

### setOngoingActivityId

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

```
public @NonNull OngoingActivity.Builder setOngoingActivityId(int ongoingActivityId)
```

Give an id to this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, as a way to reference it in `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#recoverOngoingActivity(android.content.Context,int)`

### setStaticIcon

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

```
public @NonNull OngoingActivity.Builder setStaticIcon(@NonNull Icon staticIcon)
```

Set the static icon that can be used on some surfaces to represent this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, for example in the WatchFace in ambient mode. Should be white with a transparent background, preferably a VectorDrawable.

If not set, the smallIcon of the notification will be used. If neither is set, `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#build()` will throw an exception.

### setStaticIcon

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

```
public @NonNull OngoingActivity.Builder setStaticIcon(@DrawableRes int staticIcon)
```

Set the static icon that can be used on some surfaces to represent this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, for example in the WatchFace in ambient mode. Should be white with a transparent background, preferably a VectorDrawable.

If not set, the smallIcon of the notification will be used. If neither is set, `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#build()` will throw an exception.

### setStatus

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

```
public @NonNull OngoingActivity.Builder setStatus(@NonNull Status status)
```

Set the initial status of this ongoing activity, the status may be displayed on the UI to show progress of the Ongoing Activity.

If not provided, the contentText of the notification will be used.

### setTitle

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

```
public @NonNull OngoingActivity.Builder setTitle(@Nullable String title)
```

Sets the Title of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. If this is set to a non-null value, it could be used by the launcher to override the app's title.

No defaults from the notification are used for this field.

### setTouchIntent

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

```
public @NonNull OngoingActivity.Builder setTouchIntent(@NonNull PendingIntent touchIntent)
```

Set the intent to be used to go back to the activity when the user interacts with the Ongoing Activity in other surfaces (for example, taps the Icon on the WatchFace).

If not set, the contentIntent of the notification will be used. If neither is set, `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#build()` will throw an exception.