Search in Android

Source: Internet
Author: User

We all know that the Android platform was initially launched by Google, and then Google led the establishment of OHA to continue to promote Android development. The search application may be
The most frequently used product is Google's core product, so android must be equipped with this function. This article introduces the local search framework on Android.

To talk about local search, we should first introduce the two important Android components contentprovider and contentresolver.

Contentprovider
The literal translation is "content provider". I think this image is like a data source. It helps the app or the entire platform.
Manage data. Because the data of apps on Android is independent of each other, one app cannot directly access the data of another app. With contentprovider
Different apps can access data from each other without compromising the original independence.

Contentresolver
The app exposes its own data through contentprovider, and other apps need to access this data through
Contentresolver to obtain the remote access method of the corresponding contentprovider, and then operate on the data. Contentprovider and
Contentresolver is connected through the Binder Mechanism. The relationship between each module is as follows:

Both contentprovider and contentresolver provide a query () method. You should be clear about the method name.
This method is used. In addition, there is a searchmanager module on Android that is used to process search requests. Each app must use the searchmanager module to start the search function.
 
 
There are three types of search functions on Android:
1. Network Search
2. Search for internal app Resources
3. Local Global Search
The network search function is not used in this document.
 
Search for internal app Resources
This function applies the components contentprovider and contentresolver, for example:

 

An app has the search function, so it must have two types of activity:
Searchableactivity can start the activity of the search function
Queryactivity used to complete the search and display the search results
 
Searchableactivity
When the search function is enabled, searchmanager is called, and then searchdialog is created, which is the search box we see. Enter a search keyword in the box to press the search key
Searchdialog starts queryactivity. The contentresolver query () method is called and the search result is displayed,
The search is complete.
 
 
Global Search)
This function is implemented through contentprovider and contentresolver, for example:

Start local global search by using the search box widget on the desktop. searchdialog is also created, and searchdialog sends the search request
Globalsearch module, globalsearch uses contentresolver to access
Contentprovider. After some asynchronous processing, the result is displayed on the screen.
 
Android's local retrieval function is completely based on
Contentprovider, that is, if an app does not create a contentprovider, the data of this app cannot be searched. In addition, the search efficiency is fully set.
Depending on the execution efficiency of the query () method of each contentprovider, most of the contentproviders I have seen are implemented through the database, so the search
The efficiency mainly depends on the android database SQLite.
 
This article only describes the general implementation of the search function. The source code is still relatively complex. Here we only mention it.

 

 

 

Http://blog.csdn.net/xiaohuanggougou/archive/2010/03/24/5414002.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.