# Stopwatch

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/Stopwatch.java+class:androidx.appsearch.builtintypes.Stopwatch) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***


```
@Document(name = "builtin:Stopwatch")
public class Stopwatch 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.Stopwatch](https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch) |

*** ** * ** ***

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

A stopwatch is used to count time up, starting from 0, and can be paused and resumed at will.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/androidx/appsearch/annotation/Document.BuilderProducer public final class https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch.Builder extends https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch.BuilderBase<https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch.Builder>` Builder for `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch`. |
| `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi public class https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch.BuilderBase<T extends https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch.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/Stopwatch#STATUS_PAUSED() = 3` The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch` is paused. |
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#STATUS_RESET() = 1` The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch` is reset. |
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#STATUS_RUNNING() = 2` The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch` is running. |
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#STATUS_UNKNOWN() = 0` The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch` status is unknown |

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

| ### Public methods |
|---|---|
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#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/Stopwatch#calculateCurrentAccumulatedDurationMillis(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 accumulated time in milliseconds. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#getAccumulatedDurationMillis()()` Returns the total duration in milliseconds accumulated by the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch`. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#getBaseTimeMillis()()` Returns the point in time that the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch` counts up from. |
| `long` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#getBaseTimeMillisInElapsedRealtime()()` Returns the point in time that the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch` counts up from. |
| `int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#getBootCount()()` Returns the boot count of the device when this document is last updated. |
| `@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/StopwatchLap>` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#getLaps()()` Returns all the `https://developer.android.com/reference/androidx/appsearch/builtintypes/StopwatchLap` instances. |
| `int` | `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#getStatus()()` Returns the current status. |

### 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_PAUSED

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

```
public static final int STATUS_PAUSED = 3
```

The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch` 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 = 1
```

The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch` is reset.

### STATUS_RUNNING

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

```
public static final int STATUS_RUNNING = 2
```

The `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch` is running.

### 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/Stopwatch` status is unknown

## Public constructors

### Stopwatch

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

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

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch.BuilderBase<@https://developer.android.com/reference/androidx/annotation/NonNull ?> builder` | The builder to construct the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch` 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/Stopwatch#getBootCount()`, then `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#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/Stopwatch#getBaseTimeMillis()`.

### calculateCurrentAccumulatedDurationMillis

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

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

Calculates the current accumulated time in milliseconds.

Use this method to calculate the accumulated time in real time. Use `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#getAccumulatedDurationMillis()` to get the static accumulated time stored in the document.

### getAccumulatedDurationMillis

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

```
public long getAccumulatedDurationMillis()
```

Returns the total duration in milliseconds accumulated by the `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch`.

Use this method to get the static accumulated time stored in the document. Use `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#calculateCurrentAccumulatedDurationMillis(android.content.Context)` to calculate the accumulated time in real time.

### 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/Stopwatch` counts up from. In milliseconds using the `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time base.

Use `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#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/Stopwatch` counts up from. 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/Stopwatch#getBootCount()` matches the bootCount of the current device.

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

### getLaps

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

```
public @NonNull List<StopwatchLap> getLaps()
```

Returns all the `https://developer.android.com/reference/androidx/appsearch/builtintypes/StopwatchLap` instances.

### 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/Stopwatch#STATUS_UNKNOWN()`, `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#STATUS_RESET()`, `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#STATUS_RUNNING()`, or `https://developer.android.com/reference/androidx/appsearch/builtintypes/Stopwatch#STATUS_PAUSED()`.