SearchRecentSuggestionsProvider DATABASE_MODE_2LINES 配置最近的建议以添加第二行文本。该文本从何而来?

SearchRecentSuggestionsProvider DATABASE_MODE_2LINES configures Recent Suggestions to add a second line of text. Where does that text come from?

来自 this developer guide,

The database mode must include DATABASE_MODE_QUERIES and can optionally include DATABASE_MODE_2LINES, which adds another column to the suggestions table that allows you to provide a second line of text with each suggestion.

来自 this reference doc,

public static final int DATABASE_MODE_2LINES

This mode bit configures the database to include a 2nd annotation line with each entry. optional

问题是这个注解line/text是从哪里来的?

根据我目前在开发人员指南中所读到的内容,我们没有为我们的搜索查询提供任何注释文本,这些注释文本会出现在建议中添加的额外列中 table,后来在最近的建议列表中作为第二个注释行。

在您通过调用 RecentQuerySuggestions 实例上的 saveRecentQuery(searchQuery, annotationText) 将搜索查询保存到最近查询的集合中时提供它:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent intent  = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
                MySuggestionProvider.AUTHORITY, MySuggestionProvider.MODE);
        suggestions.saveRecentQuery(query, null); // *** The second argument is that annotation text
    }
}

Reference

来自reference of saveRecentQuery

public void saveRecentQuery (String queryString, String line2)

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

Parameters queryString 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).

line2 If you have configured your recent suggestions provider with 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.