Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/provider/SearchRecentSuggestions#constants) \| [Fields](https://developer.android.com/reference/android/provider/SearchRecentSuggestions#lfields) \| [Ctors](https://developer.android.com/reference/android/provider/SearchRecentSuggestions#pubctors) \| [Methods](https://developer.android.com/reference/android/provider/SearchRecentSuggestions#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/provider/SearchRecentSuggestions#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/provider/SearchRecentSuggestions#inhmethods)

# SearchRecentSuggestions

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/provider/SearchRecentSuggestions "View this page in Kotlin") \|Java


`
public


class
SearchRecentSuggestions
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.provider.SearchRecentSuggestions |

<br />

*** ** * ** ***

This is a utility class providing access to
`https://developer.android.com/reference/android/content/SearchRecentSuggestionsProvider`.

Unlike some utility classes, this one must be instantiated and properly initialized, so that
it can be configured to operate with the search suggestions provider that you have created.

Typically, you will do this in your searchable activity, each time you receive an incoming
`https://developer.android.com/reference/android/content/Intent#ACTION_SEARCH` Intent. The code to record each
incoming query is as follows:

```text
      SearchSuggestions suggestions = new SearchSuggestions(this,
              MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);
      suggestions.saveRecentQuery(queryString, null);
 
```

For a working example, see SearchSuggestionSampleProvider and SearchQueryResults in
samples/ApiDemos/app.

### Developer Guides

For information about using search suggestions in your application, read the
[Adding Recent Query
Suggestions](https://developer.android.com/guide/topics/search/adding-recent-query-suggestions) developer guide.

<br />

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/provider/SearchRecentSuggestions#QUERIES_PROJECTION_DATE_INDEX` Index into the provided query projections. |
| `int` | `https://developer.android.com/reference/android/provider/SearchRecentSuggestions#QUERIES_PROJECTION_DISPLAY1_INDEX` Index into the provided query projections. |
| `int` | `https://developer.android.com/reference/android/provider/SearchRecentSuggestions#QUERIES_PROJECTION_DISPLAY2_INDEX` Index into the provided query projections. |
| `int` | `https://developer.android.com/reference/android/provider/SearchRecentSuggestions#QUERIES_PROJECTION_QUERY_INDEX` Index into the provided query projections. |

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/provider/SearchRecentSuggestions#QUERIES_PROJECTION_1LINE` This is the database projection that can be used to view saved queries, when configured for one-line operation. |
| ` public static final https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/provider/SearchRecentSuggestions#QUERIES_PROJECTION_2LINE` This is the database projection that can be used to view saved queries, when configured for two-line operation. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/provider/SearchRecentSuggestions#SearchRecentSuggestions(android.content.Context,%20java.lang.String,%20int)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/java/lang/String authority, int mode) ` Although provider utility classes are typically static, this one must be constructed because it needs to be initialized using the same values that you provided in your `https://developer.android.com/reference/android/content/SearchRecentSuggestionsProvider`. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/provider/SearchRecentSuggestions#clearHistory()() ` Completely delete the history. |
| ` void` | ` https://developer.android.com/reference/android/provider/SearchRecentSuggestions#saveRecentQuery(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String queryString, https://developer.android.com/reference/java/lang/String line2) ` Add a query to the recent queries list. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/provider/SearchRecentSuggestions#truncateHistory(android.content.ContentResolver,%20int)(https://developer.android.com/reference/android/content/ContentResolver cr, int maxEntries) ` Reduces the length of the history table, to prevent it from growing too large. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(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` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(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` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### QUERIES_PROJECTION_DATE_INDEX

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int QUERIES_PROJECTION_DATE_INDEX
```

Index into the provided query projections. For use with Cursor.update methods.

<br />

Constant Value:

1
(0x00000001)


### QUERIES_PROJECTION_DISPLAY1_INDEX

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int QUERIES_PROJECTION_DISPLAY1_INDEX
```

Index into the provided query projections. For use with Cursor.update methods.

<br />

Constant Value:

3
(0x00000003)


### QUERIES_PROJECTION_DISPLAY2_INDEX

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int QUERIES_PROJECTION_DISPLAY2_INDEX
```

Index into the provided query projections. For use with Cursor.update methods.

<br />

Constant Value:

4
(0x00000004)


### QUERIES_PROJECTION_QUERY_INDEX

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int QUERIES_PROJECTION_QUERY_INDEX
```

Index into the provided query projections. For use with Cursor.update methods.

<br />

Constant Value:

2
(0x00000002)


## Fields

### QUERIES_PROJECTION_1LINE

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final String[] QUERIES_PROJECTION_1LINE
```

This is the database projection that can be used to view saved queries, when
configured for one-line operation.

<br />

### QUERIES_PROJECTION_2LINE

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final String[] QUERIES_PROJECTION_2LINE
```

This is the database projection that can be used to view saved queries, when
configured for two-line operation.

<br />

## Public constructors

### SearchRecentSuggestions

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public SearchRecentSuggestions (Context context, 
                String authority, 
                int mode)
```

Although provider utility classes are typically static, this one must be constructed
because it needs to be initialized using the same values that you provided in your
`https://developer.android.com/reference/android/content/SearchRecentSuggestionsProvider`.

<br />

| Parameters ||
|---|---|
| `context` | `Context` <br /> |
| `authority` | `String`: This must match the authority that you've declared in your manifest. <br /> |
| `mode` | `int`: You can use mode flags here to determine certain functional aspects of your database. Note, this value should not change from run to run, because when it does change, your suggestions database may be wiped. <br /> |

**See also:**

- `https://developer.android.com/reference/android/content/SearchRecentSuggestionsProvider`
- `https://developer.android.com/reference/android/content/SearchRecentSuggestionsProvider#setupSuggestions(java.lang.String,%20int)`

## Public methods

### clearHistory

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void clearHistory ()
```

Completely delete the history. Use this call to implement a "clear history" UI.

Any application that implements search suggestions based on previous actions (such as
recent queries, page/items viewed, etc.) should provide a way for the user to clear the
history. This gives the user a measure of privacy, if they do not wish for their recent
searches to be replayed by other users of the device (via suggestions).

<br />

### saveRecentQuery

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void saveRecentQuery (String queryString, 
                String line2)
```

Add a query to the recent queries list. Returns immediately, performing the save
in the background.

<br />

| Parameters ||
|---|---|
| `queryString` | `String`: The string as typed by the user. This string will be displayed as the suggestion, and if the user clicks on the suggestion, this string will be sent to your searchable activity (as a new search query). <br /> |
| `line2` | `String`: If you have configured your recent suggestions provider with `https://developer.android.com/reference/android/content/SearchRecentSuggestionsProvider#DATABASE_MODE_2LINES`, you can pass a second line of text here. It will be shown in a smaller font, below the primary suggestion. When typing, matches in either line of text will be displayed in the list. If you did not configure two-line mode, or if a given suggestion does not have any additional text to display, you can pass null here. <br /> |

## Protected methods

### truncateHistory

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void truncateHistory (ContentResolver cr, 
                int maxEntries)
```

Reduces the length of the history table, to prevent it from growing too large.

<br />

| Parameters ||
|---|---|
| `cr` | `ContentResolver`: Convenience copy of the content resolver. <br /> |
| `maxEntries` | `int`: Max entries to leave in the table. 0 means remove all entries. <br /> |