ActionAccumulator


@ExperimentalAppSearchApi
class ActionAccumulator


Base class that accumulates SearchAction and ClickAction documents and stores them into AppSearch, either immediately or after a timeout.

Summary

Public functions

Unit

Cancels timers and so we can test initialization/shutdown.

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

Factory method to create an ActionAccumulator.

File

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

ListenableFuture<AppSearchBatchResult<String!, Void!>!>

Reports a TakenAction and restarts the flush timer.

ListenableFuture<AppSearchBatchResult<String!, Void!>!>

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

Public functions

cancelTimer

Added in 1.2.0-alpha01
@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-alpha01
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 AppSearchSession has a database where SearchAction and ClickAction are set.

Throws
java.util.concurrent.ExecutionException

if either SearchAction or ClickAction are not set in the provided AppSearchSession.

getCacheFile

Added in 1.2.0-alpha01
@VisibleForTesting
fun getCacheFile(): File

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

reportActionAsync

Added in 1.2.0-alpha01
fun reportActionAsync(takenAction: TakenAction): ListenableFuture<AppSearchBatchResult<String!, Void!>!>

Reports a TakenAction and restarts the flush timer.

saveDocumentsToAppSearchAsync

Added in 1.2.0-alpha01
fun saveDocumentsToAppSearchAsync(): ListenableFuture<AppSearchBatchResult<String!, Void!>!>

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