ActionAccumulator


@ExperimentalAppSearchApi
public class ActionAccumulator


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

Summary

Public methods

void

Cancels timers and so we can test initialization/shutdown.

static @NonNull ListenableFuture<ActionAccumulator>
createAsync(
    @NonNull Context context,
    @NonNull AppSearchSession appSearchSession,
    @NonNull Executor executor
)

Factory method to create an ActionAccumulator.

@NonNull File

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

@NonNull ListenableFuture<AppSearchBatchResult<StringVoid>>

Reports a TakenAction and restarts the flush timer.

@NonNull ListenableFuture<AppSearchBatchResult<StringVoid>>

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

Public methods

cancelTimer

Added in 1.2.0-alpha01
@VisibleForTesting
public void cancelTimer()

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

createAsync

Added in 1.2.0-alpha01
public static @NonNull ListenableFuture<ActionAccumulatorcreateAsync(
    @NonNull Context context,
    @NonNull AppSearchSession appSearchSession,
    @NonNull Executor executor
)

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
public @NonNull File getCacheFile()

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

reportActionAsync

Added in 1.2.0-alpha01
public @NonNull ListenableFuture<AppSearchBatchResult<StringVoid>> reportActionAsync(@NonNull TakenAction takenAction)

Reports a TakenAction and restarts the flush timer.

saveDocumentsToAppSearchAsync

Added in 1.2.0-alpha01
public @NonNull ListenableFuture<AppSearchBatchResult<StringVoid>> saveDocumentsToAppSearchAsync()

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