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

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

abstract void close()

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

abstract void close()

Closes this resource, relinquishing any underlying resources.

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.