# OngoingActivity

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) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear#1.0.0)

*** ** * ** ***


```
public final class OngoingActivity
```

<br />

*** ** * ** ***

Main class to access the Ongoing Activities API. It's created with the `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder`. After it's created (and before building and posting the `https://developer.android.com/reference/android/app/Notification.html`) `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#apply(android.content.Context)` apply needs to be called:

```
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
....
OngoingActivity ongoingActivity = new OngoingActivity.Builder(context, notificationId, builder);
....
ongoingActivity.apply(context);
notificationManager.notify(notificationId, builder.build());
```
Note that the notification passed to the `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` is also usen to take defaults if they are not explicitly set on it (see the `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` for details).

Note that if a Notification with that id was previously posted it will be replaced. If you need more than one Notification with the same ID you can use a String tag to differentiate them in both the `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#Builder(android.content.Context,java.lang.String,int,androidx.core.app.NotificationCompat.Builder)` and `https://developer.android.com/reference/android/app/NotificationManager.html#notify(java.lang.String, int, android.app.Notification)`

Afterward, `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#update(android.content.Context,androidx.wear.ongoing.Status)` can be used to update the status.

If saving the `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` instance is not convenient, it can be recovered (after the notification is posted) with `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#recoverOngoingActivity(android.content.Context)`

It's worth mentioning that the information provided may be used/redered differently on different SysUIs, so we can only provide a general expectation.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder` Builder used to build an `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#apply(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Notify the system that this activity should be shown as an Ongoing Activity. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Icon.html` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getAnimatedIcon()()` Get 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/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getCategory()()` Get the Category of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` if set, otherwise the category of the corresponding notification. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getContentDescription()()` Get the content description of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` if set. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/content/LocusIdCompat` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getLocusId()()` Get the LocusId of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, this can be used by the launcher to identify the corresponding launcher item and display it accordingly. |
| `int` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getNotificationId()()` Get the notificationId of the notification associated with this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. |
| `int` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getOngoingActivityId()()` Get the id to 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/android/graphics/drawable/Icon.html` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getStaticIcon()()` Get the static 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/Nullable.html https://developer.android.com/reference/androidx/wear/ongoing/Status` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getStatus()()` Get the 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/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getTag()()` Get the tag of the notification associated with this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, or null if there is none. |
| `long` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getTimestamp()()` Get the time (in `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` time) the OngoingActivity was built. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getTitle()()` Get the title of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` if set. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/PendingIntent.html` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#getTouchIntent()()` Get 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). |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#recoverOngoingActivity(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Convenience method for clients that don't want to / can't store the OngoingActivity instance. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` | `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#recoverOngoingActivity(android.content.Context,java.util.function.Predicate<androidx.wear.ongoing.OngoingActivity>)( @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/util/function/Predicate.html<https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity> filter )` Convenience method for clients that don't want to / can't store the OngoingActivity instance. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` | `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/android/content/Context.html context, int ongoingActivityId)` Convenience method for clients that don't want to / can't store the OngoingActivity instance. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/RequiresPermission(value = https://developer.android.com/reference/android/Manifest.permission.html#POST_NOTIFICATIONS) https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#update(android.content.Context,androidx.wear.ongoing.Status)(@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/androidx/wear/ongoing/Status status)` Update the status of this Ongoing Activity. |

## Public methods

### apply

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

```
public void apply(@NonNull Context context)
```

Notify the system that this activity should be shown as an Ongoing Activity. This will modify the notification builder associated with this Ongoing Activity, so needs to be called before building and posting that notification.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | May be used to access system services. A reference will not be kept after this call returns. |

### getAnimatedIcon

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

```
public @Nullable Icon getAnimatedIcon()
```

Get 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.

### getCategory

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

```
public @Nullable String getCategory()
```

Get the Category of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` if set, otherwise the category of the corresponding notification.

### getContentDescription

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

```
public @Nullable String getContentDescription()
```

Get the content description of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` if set.

### getLocusId

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

```
public @Nullable LocusIdCompat getLocusId()
```

Get the LocusId of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, this can be used by the launcher to identify the corresponding launcher item and display it accordingly. If not set, returns the one in the corresponding Notification.

### getNotificationId

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

```
public int getNotificationId()
```

Get the notificationId of the notification associated with this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`.

### getOngoingActivityId

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

```
public int getOngoingActivityId()
```

Get the id to this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. This id is used to reference it in `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity#recoverOngoingActivity(android.content.Context,int)`

### getStaticIcon

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

```
public @NonNull Icon getStaticIcon()
```

Get 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. If not set, returns the small icon of the corresponding Notification.

### getStatus

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

```
public @Nullable Status getStatus()
```

Get the status of this ongoing activity, the status may be displayed on the UI to show progress of the Ongoing Activity. If not set, returns the content text of the corresponding Notification.

### getTag

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

```
public @Nullable String getTag()
```

Get the tag of the notification associated with this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`, or null if there is none.

### getTimestamp

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

```
public long getTimestamp()
```

Get the time (in `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` time) the OngoingActivity was built.

### getTitle

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

```
public @Nullable String getTitle()
```

Get the title of this `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` if set.

### getTouchIntent

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

```
public @NonNull PendingIntent getTouchIntent()
```

Get 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, returns the touch intent of the corresponding Notification.

### recoverOngoingActivity

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

```
public static @Nullable OngoingActivity recoverOngoingActivity(@NonNull Context context)
```

Convenience method for clients that don't want to / can't store the OngoingActivity instance. Note that if there is more than one Ongoing Activity active you have not guarantee over which one you get, you need to use one of the other variations of this method.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | May be used to access system services. A reference will not be kept after this call returns. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` | the Ongoing Activity or null if not found |

### recoverOngoingActivity

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

```
public static @Nullable OngoingActivity recoverOngoingActivity(
    @NonNull Context context,
    @NonNull Predicate<OngoingActivity> filter
)
```

Convenience method for clients that don't want to / can't store the OngoingActivity instance.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | May be used to access system services. A reference will not be kept after this call returns. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/function/Predicate.html<https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity> filter` | used to find the required `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity`. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` | the Ongoing Activity or null if not found |

### recoverOngoingActivity

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

```
public static @Nullable OngoingActivity recoverOngoingActivity(@NonNull Context context, int ongoingActivityId)
```

Convenience method for clients that don't want to / can't store the OngoingActivity instance.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | May be used to access system services. A reference will not be kept after this call returns. |
| `int ongoingActivityId` | the id of the Ongoing Activity to retrieve, set in `https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity.Builder#setOngoingActivityId(int)` |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/wear/ongoing/OngoingActivity` | the Ongoing Activity or null if not found |

### update

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

```
@RequiresPermission(value = Manifest.permission.POST_NOTIFICATIONS)
public void update(@NonNull Context context, @NonNull Status status)
```

Update the status of this Ongoing Activity. Note that this may post the notification updated with the new information.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | May be used to access system services. A reference will not be kept after this call returns. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/ongoing/Status status` | The new status of this Ongoing Activity. |