# ActionAccumulator

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/usagereporting/ActionAccumulator.java+class:androidx.appsearch.usagereporting.ActionAccumulator) Added in [1.2.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

*** ** * ** ***


```
@ExperimentalAppSearchApi
class ActionAccumulator
```

<br />

*** ** * ** ***

Base class that accumulates `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction` and `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ClickAction` documents and stores them into AppSearch, either immediately or after a timeout.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ClickAction` |   |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction` |   |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction` |   |

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ActionAccumulator#cancelTimer()()` Cancels timers and so we can test initialization/shutdown. |
| `java-static https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ActionAccumulator!>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ActionAccumulator#createAsync(android.content.Context,androidx.appsearch.app.AppSearchSession,java.util.concurrent.Executor)( context: https://developer.android.com/reference/android/content/Context.html, appSearchSession: https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchSession, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html )` Factory method to create an ActionAccumulator. |
| `https://developer.android.com/reference/java/io/File.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ActionAccumulator#getCacheFile()()` Returns the cache file to use for on-disk caching. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchBatchResult<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://developer.android.com/reference/java/lang/Void.html!>!>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ActionAccumulator#reportActionAsync(androidx.appsearch.usagereporting.TakenAction)(takenAction: https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction)` Reports a `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction` and restarts the flush timer. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchBatchResult<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://developer.android.com/reference/java/lang/Void.html!>!>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ActionAccumulator#saveDocumentsToAppSearchAsync()()` Saves the documents in the cache to AppSearch and deletes the cache file. |

## Public functions

### cancelTimer

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

```
@VisibleForTesting
fun cancelTimer(): Unit
```

Cancels timers and so we can test initialization/shutdown. This simulates closing the app using the ActionAccumulator

### createAsync

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

```
java-static fun createAsync(
    context: Context,
    appSearchSession: AppSearchSession,
    executor: Executor
): ListenableFuture<ActionAccumulator!>
```

Factory method to create an ActionAccumulator.

Initializing and using the ActionAccumulator requires that the provided `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchSession` has a database where `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction` and `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ClickAction` are set.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/ExecutionException.html` | if either `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/SearchAction` or `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/ClickAction` are not set in the provided `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchSession`. |

### getCacheFile

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

```
@VisibleForTesting
fun getCacheFile(): File
```

Returns the cache file to use for on-disk caching.

### reportActionAsync

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

```
fun reportActionAsync(takenAction: TakenAction): ListenableFuture<AppSearchBatchResult<String!, Void!>!>
```

Reports a `https://developer.android.com/reference/kotlin/androidx/appsearch/usagereporting/TakenAction` and restarts the flush timer.

### saveDocumentsToAppSearchAsync

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

```
fun saveDocumentsToAppSearchAsync(): ListenableFuture<AppSearchBatchResult<String!, Void!>!>
```

Saves the documents in the cache to AppSearch and deletes the cache file.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/exceptions/AppSearchException` |   |