OngoingActivity
public
final
class
OngoingActivity
extends Object
java.lang.Object | |
↳ | androidx.wear.ongoing.OngoingActivity |
Main class to access the Ongoing Activities API.
It's created with the OngoingActivity.Builder
. After it's created (and before building and
posting the Notification
) 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 fromExistingOngoingActivity(Context)
Summary
Nested classes | |
---|---|
class |
OngoingActivity.Builder
Builder used to build an |
Public methods | |
---|---|
void
|
apply(Context context)
Notify the system that this activity should be shown as an Ongoing Activity. |
static
OngoingActivity
|
fromExistingOngoingActivity(Context context)
Convenience method for clients that don’t want to / can’t store the OngoingActivity instance. |
static
OngoingActivity
|
fromExistingOngoingActivity(Context context, Predicate<OngoingActivityData> filter)
Convenience method for clients that don’t want to / can’t store the OngoingActivity instance. |
static
OngoingActivity
|
fromExistingOngoingActivity(Context context, int ongoingActivityId)
Convenience method for clients that don’t want to / can’t store the OngoingActivity instance. |
void
|
update(Context context, OngoingActivityStatus status)
Update the status of this Ongoing Activity. |
Inherited methods | |
---|---|
Public methods
apply
public void apply (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 | |
---|---|
context |
Context : May be used to access system services. A reference will not be kept after
this call returns.
|
fromExistingOngoingActivity
public static OngoingActivity fromExistingOngoingActivity (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 | |
---|---|
context |
Context : May be used to access system services. A reference will not be kept after
this call returns. |
Returns | |
---|---|
OngoingActivity |
the Ongoing Activity or null if not found |
fromExistingOngoingActivity
public static OngoingActivity fromExistingOngoingActivity (Context context, Predicate<OngoingActivityData> filter)
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 : used to find the required OngoingActivity . |
Returns | |
---|---|
OngoingActivity |
the Ongoing Activity or null if not found |
fromExistingOngoingActivity
public static OngoingActivity fromExistingOngoingActivity (Context context, int ongoingActivityId)
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) |
Returns | |
---|---|
OngoingActivity |
the Ongoing Activity or null if not found |
update
public void update (Context context, OngoingActivityStatus status)
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.
|
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-01-27 UTC.