Search is a core user feature on Android. Users should be able to search any data that is available to them, whether the content is located on the device or the Internet. The search experience should be seamless and consistent across the entire system, which is why Android provides a search framework to help you provide users with a familiar search dialog and a great search experience.
Android's search framework provides a user interface in which users can perform a search and an interaction layer that communicates with your application, so you don't have to build your own search Activity. Instead, a search dialog appears at the top of the screen at the user's command without interrupting the current Activity.
The search framework manages the life of the search dialog. When users execute a search, the search framework passes the query text to your application so your application can perform a search. Figure 1 shows an example of the search dialog with optional search suggestions.
Once your application is set up to use the search dialog, you can:
Note: The search framework does not provide APIs to
search your data. To perform a search, you need to use APIs appropriate for your data. For example,
if your data is stored in an SQLite database, you should use the android.database.sqlite
APIs to perform searches.
The following documents show you how to use the search dialog in your application:
When you implement search in your application, take steps to protect the user's privacy. Many users consider their activities on the phone—including searches—to be private information. To protect each user's privacy, you should abide by the following principles:
Personal information is any information that can personally identify your users, such as their names, email addresses, billing information, or other data that can be reasonably linked to such information. If your application implements search with the assistance of a server, avoid sending personal information along with the search queries. For example, if you are searching for businesses near a zip code, you don't need to send the user ID as well; send only the zip code to the server. If you must send the personal information, you should not log it. If you must log it, protect that data very carefully and erase it as soon as possible.
The search framework helps your application provide context-specific suggestions while the user
types. Sometimes these
suggestions are based on previous searches or other actions taken by the user in an earlier
session. A user might not wish for previous searches to be revealed to other device users, for
instance, if they share their phone with a friend. If your application provides suggestions that can
reveal previous activities, you should implement the ability for the user to clear the search
history. If you are using SearchRecentSuggestions
, you can simply call the
clearHistory()
method. If you are implementing
custom suggestions, you'll need to provide a similar "clear history" method in your provider that
the user can execute.