Android 12 Developer Preview is here! Try it out, and give us your feedback!

OngoingActivity

@RequiresApi(24) class OngoingActivity
kotlin.Any
   ↳ androidx.wear.ongoing.OngoingActivity

Main class to access the Ongoing Activities API. It's created with the Builder. After it's created (and before building and posting the Notification) OngoingActivity#apply(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()); Afterward, update can be used to update the status. If saving the OngoingActivity instance is not convenient, it can be recovered (after the notification is posted) with OngoingActivity#fromExistingOngoingActivity(Context)

Summary

Nested classes

Builder used to build an OngoingActivity

Public methods
Unit
apply(@NonNull context: Context)

Notify the system that this activity should be shown as an Ongoing Activity.

static OngoingActivity?
fromExistingOngoingActivity(@NonNull context: Context, @NonNull filter: Predicate<OngoingActivityData!>)

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

static OngoingActivity?

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

static OngoingActivity?
fromExistingOngoingActivity(@NonNull context: Context, ongoingActivityId: Int)

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

Unit
update(@NonNull context: Context, @NonNull status: OngoingActivityStatus)

Update the status of this Ongoing Activity.

Public methods

apply

fun apply(@NonNull context: Context): Unit

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
context Context: May be used to access system services. A reference will not be kept after this call returns.

fromExistingOngoingActivity

@Nullable static fun fromExistingOngoingActivity(
    @NonNull context: Context,
    @NonNull filter: Predicate<OngoingActivityData!>
): OngoingActivity?

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

Parameters
context Context: May be used to access system services. A reference will not be kept after this call returns.
filter Predicate<OngoingActivityData!>: used to find the required OngoingActivity.
Return
OngoingActivity? the Ongoing Activity or null if not found

fromExistingOngoingActivity

@Nullable static fun fromExistingOngoingActivity(@NonNull context: Context): OngoingActivity?

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
context Context: May be used to access system services. A reference will not be kept after this call returns.
Return
OngoingActivity? the Ongoing Activity or null if not found

fromExistingOngoingActivity

@Nullable static fun fromExistingOngoingActivity(
    @NonNull context: Context,
    ongoingActivityId: Int
): OngoingActivity?

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

Parameters
context Context: May be used to access system services. A reference will not be kept after this call returns.
ongoingActivityId Int: the id of the Ongoing Activity to retrieve, set in OngoingActivity.Builder#setOngoingActivityId(int)
Return
OngoingActivity? the Ongoing Activity or null if not found

update

fun update(
    @NonNull context: Context,
    @NonNull status: OngoingActivityStatus
): Unit

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

Parameters
context Context: May be used to access system services. A reference will not be kept after this call returns.
status OngoingActivityStatus: The new status of this Ongoing Activity.