1

I have quite a few activities in my android app and need to implement an ActionBar with a SearchView.

I initially just added the following lines to my SearchActivity:

 <activity android:name=".activity.SearchActivity" 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>

However, searchManager.getSearchableInfo(getComponentName()); returned null in onCreateOptionsMenu when invoked from AnotherActivity1.

So I also added the intent-filter and android.app.searchable meta-data to AnotherActivity1 and that works for the AnotherActivity1 SearchView.

But I have many such activities - am I supposed to just copy-paste this XML snippet for all of them or is there some more elegant solution I'm missing?

1 Answer 1

0

Hmm, I think I figured it out myself.

Use

searchManager.getSearchableInfo(new ComponentName(this, SearchActivity.class));

instead of

searchManager.getSearchableInfo(getComponentName());

Then I have to apply the intent-filter and meta-data only to SearchActivity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.