Added in API level 31

SearchResults

public class SearchResults
extends Object implements Closeable

java.lang.Object
   ↳ android.app.appsearch.SearchResults


Encapsulates results of a search operation.

Each AppSearchSession#search operation returns a list of SearchResult objects, referred to as a "page", limited by the size configured by SearchSpec.Builder.setResultCountPerPage(int).

To fetch a page of results, call getNextPage(Executor, Consumer).

All instances of SearchResults must call SearchResults#close() after the results are fetched.

This class is not thread safe.

Summary

Public methods

void close()

Closes this stream and releases any system resources associated with it.

void getNextPage(Executor executor, Consumer<AppSearchResult<List<SearchResult>>> callback)

Retrieves the next page of SearchResult objects.

Inherited methods

Public methods

close

Added in API level 31
public void close ()

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

getNextPage

Added in API level 31
public void getNextPage (Executor executor, 
                Consumer<AppSearchResult<List<SearchResult>>> callback)

Retrieves the next page of SearchResult objects.

The page size is configured by SearchSpec.Builder#setResultCountPerPage.

Continue calling this method to access results until it returns an empty list, signifying there are no more results.

Parameters
executor Executor: Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

callback Consumer: Callback to receive the pending result of performing this operation. This value cannot be null.