# 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")
class Timer : Thing
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.appsearch.builtintypes.Thing](https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing) ||
|   | ↳ | [androidx.appsearch.builtintypes.Timer](https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer) |

*** ** * ** ***

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

## Summary

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

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

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#Timer(androidx.appsearch.builtintypes.Timer.BuilderBase<?>)(builder: https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer.BuilderBase<*>)` Constructor for `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#calculateBaseTimeMillis(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` Calculates the base time in milliseconds using the `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time base. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#calculateCurrentRemainingDurationMillis(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` Calculates the current remaining time in milliseconds. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#calculateExpirationTimeMillis(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` Calculates the expire time in milliseconds in the `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time base. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#getBaseTimeMillis()()` Returns the point in time that the `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer` counts down from, relative to its `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#getRemainingDurationMillis()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#getBaseTimeMillisInElapsedRealtime()()` Returns the point in time that the `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer` counts down from, relative to its `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#getRemainingDurationMillis()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#getBootCount()()` Returns the boot count of the device when this document is last updated. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#getDurationMillis()()` Returns the total duration in milliseconds, including additional time added by the user. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#getOriginalDurationMillis()()` Returns the original duration in milliseconds when the `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer` was first created. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#getRemainingDurationMillis()()` Returns the amount of time remaining in milliseconds for the `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer` relative to its `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#getBaseTimeMillis()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/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. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/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. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#getStatus()()` Returns the current status. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#shouldVibrate()()` Returns whether or not to activate the device vibrator when the `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer` expires. |

### Inherited functions

From [androidx.appsearch.builtintypes.Thing](https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing) `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>` `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing#getAlternateNames()()`

Returns an unmodifiable list of aliases, if any, for this item.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing#getCreationTimestampMillis()()`

Returns the creation timestamp, in milliseconds since Unix epoch, of this item.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing#getDescription()()`

Returns a description of this item.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing#getDocumentScore()()`

Returns the intrinsic score (or importance) of this item.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing#getDocumentTtlMillis()()`

Returns the time-to-live timestamp, in milliseconds since `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing#getCreationTimestampMillis()`, for this item.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing#getId()()`

Returns the unique identifier for this item.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi
https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing#getImage()()`

Returns the URL for an image of this item.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing#getName()()`

Returns the name of this item.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing#getNamespace()()`

Returns the namespace (or logical grouping) for this item.
`(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/PotentialAction!>` `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi
https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Thing#getPotentialActions()()`

Returns the actions that can be taken on this object.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` `https://developer.android.com/reference/kotlin/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)

```
const val STATUS_EXPIRED = 3: Int
```

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

### STATUS_MISSED

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

```
const val STATUS_MISSED = 4: Int
```

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

### STATUS_PAUSED

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

```
const val STATUS_PAUSED = 2: Int
```

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

### STATUS_RESET

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

```
const val STATUS_RESET = 5: Int
```

The `https://developer.android.com/reference/kotlin/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)

```
const val STATUS_STARTED = 1: Int
```

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

### STATUS_UNKNOWN

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

```
const val STATUS_UNKNOWN = 0: Int
```

The `https://developer.android.com/reference/kotlin/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
Timer(builder: Timer.BuilderBase<*>)
```

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

| Parameters |
|---|---|
| `builder: https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer.BuilderBase<*>` | The builder to construct the `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer` from. |

## Public functions

### calculateBaseTimeMillis

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

```
fun calculateBaseTimeMillis(context: Context): Long
```

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/kotlin/androidx/appsearch/builtintypes/Timer#getBootCount()`, then `https://developer.android.com/reference/kotlin/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/kotlin/androidx/appsearch/builtintypes/Timer#getBaseTimeMillis()`.

### calculateCurrentRemainingDurationMillis

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

```
fun calculateCurrentRemainingDurationMillis(context: Context): Long
```

Calculates the current remaining time in milliseconds.

A negative value may be returned if the `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer` is `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#STATUS_MISSED()` or `https://developer.android.com/reference/kotlin/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/kotlin/androidx/appsearch/builtintypes/Timer#getRemainingDurationMillis()` to get the static remaining time stored in the document.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The app context |

### calculateExpirationTimeMillis

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

```
fun calculateExpirationTimeMillis(context: Context): Long
```

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/kotlin/androidx/appsearch/builtintypes/Timer` is `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#STATUS_PAUSED()` or `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#STATUS_RESET()`.

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

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The app context |

### getBaseTimeMillis

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

```
fun getBaseTimeMillis(): Long
```

Returns the point in time that the `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer` counts down from, relative to its `https://developer.android.com/reference/kotlin/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/kotlin/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)

```
fun getBaseTimeMillisInElapsedRealtime(): Long
```

Returns the point in time that the `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer` counts down from, relative to its `https://developer.android.com/reference/kotlin/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/kotlin/androidx/appsearch/builtintypes/Timer#getBootCount()` matches the bootCount of the current device. It is used to calculate `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer#calculateExpirationTimeMillis(android.content.Context)`

`https://developer.android.com/reference/kotlin/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)

```
fun getBootCount(): Int
```

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/kotlin/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)

```
fun getDurationMillis(): Long
```

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)

```
fun getOriginalDurationMillis(): Long
```

Returns the original duration in milliseconds when the `https://developer.android.com/reference/kotlin/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)

```
fun getRemainingDurationMillis(): Long
```

Returns the amount of time remaining in milliseconds for the `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Timer` relative to its `https://developer.android.com/reference/kotlin/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/kotlin/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)

```
fun getRingtone(): String?
```

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)

```
fun getStartTimeMillis(): Long
```

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)

```
fun getStatus(): Int
```

Returns the current status.

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

### shouldVibrate

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

```
fun shouldVibrate(): Boolean
```

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