# Timer

Artifact: [androidx.appsearch:appsearch-builtin-types](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/builtintypes/Timer.java+class:androidx.appsearch.builtintypes.Timer) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***


```
@Document(name = "builtin:Timer")
public class Timer extends Thing
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.appsearch.builtintypes.Thing](https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing) ||
|   | ↳ | [androidx.appsearch.builtintypes.Timer](https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer) |

*** ** * ** ***

AppSearch document representing a `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` entity.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/androidx/appsearch/annotation/Document.BuilderProducer public final class https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer.Builder extends https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer.BuilderBase<https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer.Builder>` Builder for `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer`. |
| `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi public class https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer.BuilderBase<T extends https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer.BuilderBase<T>> extends https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing.BuilderBase<T>` |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_EXPIRED() = 3` The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is expired. |
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_MISSED() = 4` The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is missed. |
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_PAUSED() = 2` The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is paused. |
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_RESET() = 5` The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is reset to its initial value. |
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_STARTED() = 1` The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is started. |
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_UNKNOWN() = 0` The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is in an unknown error state. |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#Timer(androidx.appsearch.builtintypes.Timer.BuilderBase<?>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer.BuilderBase<@https://developer.android.com/reference/androidx/annotation/NonNull ?> builder)` Constructor for `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer`. |

| ### Public methods |
|---|---|
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#calculateBaseTimeMillis(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Calculates the base time in milliseconds using the `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time base. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#calculateCurrentRemainingDurationMillis(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Calculates the current remaining time in milliseconds. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#calculateExpirationTimeMillis(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Calculates the expire time in milliseconds in the `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time base. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getBaseTimeMillis()()` Returns the point in time that the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` counts down from, relative to its `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getRemainingDurationMillis()`. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getBaseTimeMillisInElapsedRealtime()()` Returns the point in time that the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` counts down from, relative to its `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getRemainingDurationMillis()`. |
| `int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getBootCount()()` Returns the boot count of the device when this document is last updated. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getDurationMillis()()` Returns the total duration in milliseconds, including additional time added by the user. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getOriginalDurationMillis()()` Returns the original duration in milliseconds when the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` was first created. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getRemainingDurationMillis()()` Returns the amount of time remaining in milliseconds for the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` relative to its `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getBaseTimeMillis()`. |
| `@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/appsearch/builtintypes/Timer#getRingtone()()` Returns the ringtone as a content URI to be played, or `https://developer.android.com/reference/android/provider/AlarmClock.html#VALUE_RINGTONE_SILENT` if no ringtone will be played. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getStartTimeMillis()()` Returns the start time in milliseconds using the `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time base. |
| `int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getStatus()()` Returns the current status. |
| `boolean` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#shouldVibrate()()` Returns whether or not to activate the device vibrator when the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` expires. |

### Inherited methods

From [androidx.appsearch.builtintypes.Thing](https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing) `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html>` `https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing#getAlternateNames()()`

Returns an unmodifiable list of aliases, if any, for this item.
`long` `https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing#getCreationTimestampMillis()()`

Returns the creation timestamp, in milliseconds since Unix epoch, of this item.
`@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/appsearch/builtintypes/Thing#getDescription()()`

Returns a description of this item.
`int` `https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing#getDocumentScore()()`

Returns the intrinsic score (or importance) of this item.
`long` `https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing#getDocumentTtlMillis()()`

Returns the time-to-live timestamp, in milliseconds since `https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing#getCreationTimestampMillis()`, for this item.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing#getId()()`

Returns the unique identifier for this item.
`@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/appsearch/app/ExperimentalAppSearchApi
https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing#getImage()()`

Returns the URL for an image of this item.
`@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/appsearch/builtintypes/Thing#getName()()`

Returns the name of this item.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing#getNamespace()()`

Returns the namespace (or logical grouping) for this item.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/appsearch/builtintypes/PotentialAction>` `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi
https://developer.android.com/reference/androidx/appsearch/builtintypes/Thing#getPotentialActions()()`

Returns the actions that can be taken on this object.
`@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/appsearch/builtintypes/Thing#getUrl()()`

Returns the deeplink URL of this item.

## Constants

### STATUS_EXPIRED

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

```
public static final int STATUS_EXPIRED = 3
```

The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is expired.

### STATUS_MISSED

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

```
public static final int STATUS_MISSED = 4
```

The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is missed.

### STATUS_PAUSED

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

```
public static final int STATUS_PAUSED = 2
```

The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is paused.

### STATUS_RESET

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

```
public static final int STATUS_RESET = 5
```

The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is reset to its initial value.

### STATUS_STARTED

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

```
public static final int STATUS_STARTED = 1
```

The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is started.

### STATUS_UNKNOWN

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

```
public static final int STATUS_UNKNOWN = 0
```

The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is in an unknown error state.

## Public constructors

### Timer

Added in [1.2.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

```
@ExperimentalAppSearchApi
public Timer(@NonNull Timer.BuilderBase<@NonNull ?> builder)
```

Constructor for `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer.BuilderBase<@https://developer.android.com/reference/androidx/annotation/NonNull ?> builder` | The builder to construct the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` from. |

## Public methods

### calculateBaseTimeMillis

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

```
public long calculateBaseTimeMillis(@NonNull Context context)
```

Calculates the base time in milliseconds using the `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time base.

If the boot count retrieved from the context matches `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getBootCount()`, then `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getBaseTimeMillisInElapsedRealtime()` will be used to calculate the base time in the `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time base. Otherwise return `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getBaseTimeMillis()`.

### calculateCurrentRemainingDurationMillis

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

```
public long calculateCurrentRemainingDurationMillis(@NonNull Context context)
```

Calculates the current remaining time in milliseconds.

A negative value may be returned if the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_MISSED()` or `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_EXPIRED()` to indicate it has already fired.

Use this method to calculate the remaining time at runtime. Use `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getRemainingDurationMillis()` to get the static remaining time stored in the document.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The app context |

### calculateExpirationTimeMillis

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

```
public long calculateExpirationTimeMillis(@NonNull Context context)
```

Calculates the expire time in milliseconds in the `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time base.

`https://developer.android.com/reference/java/lang/Long.html#MAX_VALUE` will be returned if the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_PAUSED()` or `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_RESET()`.

A negative value may be returned if the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` is `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_MISSED()` or `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_EXPIRED()` to indicate it expired in the past.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The app context |

### getBaseTimeMillis

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

```
public long getBaseTimeMillis()
```

Returns the point in time that the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` counts down from, relative to its `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getRemainingDurationMillis()`. In milliseconds using the `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time base.

The expire time of the Timer can be calculated using the sum of its base time and remaining time.

Use `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#calculateBaseTimeMillis(android.content.Context)` to get a more accurate base time that accounts for the current boot count of the device.

### getBaseTimeMillisInElapsedRealtime

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

```
public long getBaseTimeMillisInElapsedRealtime()
```

Returns the point in time that the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` counts down from, relative to its `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getRemainingDurationMillis()`. In milliseconds using the `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` time base.

ElapsedRealtime should only be used if the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getBootCount()` matches the bootCount of the current device. It is used to calculate `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#calculateExpirationTimeMillis(android.content.Context)`

`https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#calculateExpirationTimeMillis(android.content.Context)`

### getBootCount

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

```
public int getBootCount()
```

Returns the boot count of the device when this document is last updated.

The boot count of the device can be accessed from Global Settings. See `https://developer.android.com/reference/android/provider/Settings.Global.html#BOOT_COUNT`.

On older APIs where boot count is not available, this value should not be used.

If available, this value is used to calculate `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#calculateExpirationTimeMillis(android.content.Context)`.

### getDurationMillis

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

```
public long getDurationMillis()
```

Returns the total duration in milliseconds, including additional time added by the user.

Applications may allow the user to add additional durations. The durationMillis will always return the new updated duration.

### getOriginalDurationMillis

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

```
public long getOriginalDurationMillis()
```

Returns the original duration in milliseconds when the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` was first created.

Applications may allow the user to add additional durations. The originalDurationMillis will always return the original duration before any change has taken place.

### getRemainingDurationMillis

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

```
public long getRemainingDurationMillis()
```

Returns the amount of time remaining in milliseconds for the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` relative to its `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#getBaseTimeMillis()`.

The expire time of the Timer can be calculated using the sum of its base time and remaining time.

Use this method to get the static remaining time stored in the document. Use `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#calculateCurrentRemainingDurationMillis(android.content.Context)` to calculate the remaining time at runtime.

### getRingtone

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

```
public @Nullable String getRingtone()
```

Returns the ringtone as a content URI to be played, or `https://developer.android.com/reference/android/provider/AlarmClock.html#VALUE_RINGTONE_SILENT` if no ringtone will be played.

### getStartTimeMillis

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

```
public long getStartTimeMillis()
```

Returns the start time in milliseconds using the `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time base.

The start time is the first time that a new Timer, or a Timer that has been reset is started. Pausing and resuming should not change its start time.

### getStatus

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

```
public int getStatus()
```

Returns the current status.

Status can be `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_UNKNOWN()`, `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_STARTED()`, `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_PAUSED()`, `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_EXPIRED()`, `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_MISSED()`, or `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer#STATUS_RESET()`.

### shouldVibrate

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

```
public boolean shouldVibrate()
```

Returns whether or not to activate the device vibrator when the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Timer` expires.