Вопрос

IMO,The search action contains two process "collect user input" and "do the search job".

Every process need a activity to alive, that's to say the "collect user input" should be located in an Activity, so is the "do the search job".

As the guide said:

When the user executes a search from the search dialog or a search widget, the system creates an Intent and stores the user query in it. The system then starts the activity that you've declared to handle searches (the "searchable activity") and delivers it the intent.

This make me think as the JSP page, a.jsp contains a form to collect user input, and the form will be submit to b.jsp or something else.

Suppose I have an ActivityA which holds the search widget, and ActivityB to handle the search(This should be the so side SearchableActivity).

Now I wonder if the ActivityA and ActivityB should be the same one?

Take the following xml congratulation:

    <activity
        android:name="com.app.MainActivity"
        android:label="@string/title_activity_main"
        android:launchMode="singleTop" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>

        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable" />
    </activity>

Does it mean that the MapActivity will handle all the Search request from the whole application or it can only handle the Search request for the MapActivity only?

Это было полезно?

Решение

From the document

A searchable activity is the Activity in your application that performs searches based on a query string and presents the search results.

When the user executes a search in the search dialog or widget, the system starts your searchable activity and delivers it the search query in an Intent with the ACTION_SEARCH action. Your searchable activity retrieves the query from the intent's QUERY extra, then searches your data and presents the results.

Thus your android.app.searchable activity can/will handle all the Search request from the whole application if you define it to other activities as their search activity is your serchable activity.

<activity android:name=".OtherActivity" ... >
    <!-- enable the search dialog to send searches to SearchableActivity -->
    <meta-data android:name="android.app.default_searchable"
               android:value="com.app.MainActivity" />
</activity>

http://developer.android.com/guide/topics/search/search-dialog.html

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top