Android Search In Pictures

You can see Quick Search Box at the top. You can start entering searches there directly.

You can invoke search also through the magnifying glass icon on the right hand side menu button group.

you can use this search button on the right any time in your device experience.

If there is an activity then this button will bring the search as directed by that activity. This will be either local search or a global search.

If you don't type anything in the search box, the system is capable of displaying a list of applicable things based on previous searches. In this case I have invoked the spare parts application through a search. The system determined that it is reasonable to go there again and hence suggested the app.

This provision is available for all your applications to suggest.

I have typed "a" to start the search. At this time the cursor is in the search box, none of the options are high lighted due to moving arrow buttons. In this mode half the screen is filled with suggestions and the other half is taken by the key board. In the next screen you will see what happens if you use the arrow down key to move through the suggestions.

In this case, I have used the move down arrow to go through the list of suggestions. As soon as this happens Android will remove the keyboard and fill the whole page with suggestions. It will put the keyboard back if you were to navigate back to the edit control.

Notice what happens when the move down button take you to an item like above. In this case Android took the suggestion and populated the search box. Now you have the option of selecting the search button at the top or directly clicking on the suggestion itself.

Notice that the letter "a" is replaced by the suggestion text in the search edit box.

Notice how pointing to an application suggestion does not change the search box. Now two things can happen.

If you click on the search icon (magnifying glass) next to the search box, google browser will be launched.

if you click on the application name item in the suggestion list then the application will be launched.

Notice how finally when I clicked the magnifying glass with an "a" in the text box, it launched the browser and searched for contents.

Your application can participate in the global search box as well. It does this by registering a suggestion provider. Once such an application is installed, as a user you will need to enable the application to participate in the suggestions. By default you will not see the suggestions from this application. You can use the following figures to accomplish this.

You can get to this screen by clicking on Home and then clicking on the arrow up at the bottom. This is essentially the list of apps on your phone.

Nothing terribly special the menu previous will lead to this view on which you will select the "search"

You will now need to click on the searchable items menu.

You will see the list of available apps here. See the grayed out app here called "Test Harness 1". This is the app I have installed. By default it is not enabled as you can see from the grayed out menu.

The next sequence of images will show you how the suggestions from this app "Test Harness 1" will show up in the global search box.

Notice that multiple suggestions from mutltiple apps are put together into a single line. At this level you won't see the individual suggestions from each app. You have to click on it to expand it.

See how the light gray background expanded the list. Now you see the individual items, still combined, under each app. You will have to choose your app to see the real items.

Notice that these suggestions are now dedicated to your app. Any action on this view will invoke your specific search activity.

This is what you would see if you were to click the search button while your activity is in focus. Android will invoke the local search along with local suggestions. This is also assuming that your activity has opted for a local search and not a global one.

The following figures will focus on demonstrating how regular activities interact with the search key. In other words, what happens when you click on search when you are viewing an activity.

I will cover the following types activities.

I will start with a regular activity that is unaware of any search. I will examine what happens when the search key is pressed when this activity is the current activity in focus.

Then I will try an activity that explicitly disables search and see how the search key behaves.

I will then look at an activity which is configured for local search. I will see what happens when the search key is pressed when this activity is in focus.

Here are the annotated figures exploring these scenarios.

As the comment suggests if you press the search key NOTHING-HAPPENS. This is because the activity has returned false from the onSearchRequested() function of this activity.

This activity is not specialized in any way. It is a standard regular activity except that I created a menu option called "Search". I could have used any text I would have wanted.

when this menu item is chosen Android will invoke the global search. Here is the code that does it.


if (item.getItemId() == R.id.mid_si_search)
{
this.onSearchRequested();
return true;
}


<activity android:name=".LocalSearchEnabledActivity"
           android:label="Activity/QSB Interaction::Local Search">
   <meta-data android:name="android.app.default_searchable"
      android:value=".SearchActivity" />
</activity>

Notice how the LocalSearchEnabledActivity indicates that there is an activity called SearchActivity that can respond to searches. we will see shortly what this searchactivity is.

when the previous activity is in view and user presses the search key you will see this local search dialog shows up. You can recognize this local aspect by looking at the label of this search dialog and also the hint in the QSB edit box.

If you type something in here and click the search icon you will be taken to the above specified SearchActivity which you will see in the next figure.

Android is the one that invokes this activity by passing the query text. To make this happen this search activity should have two definitions. One in the manifest file and one in the xml sub directory. You will see them next


<activity android:name=".SearchActivity"
           android:label="Activity/QSB Interaction::Search Results">
     <intent-filter>
        <action android:name="android.intent.action.SEARCH" />
        <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
     <meta-data android:name="android.app.searchable"
         android:resource="@xml/searchable" />
</activity>

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/search_label"
    android:hint="@string/search_hint" 
    android:searchMode="showSearchLabelAsBadge"
/>

Notice the serch label and search hint.