Why is There no Configuration by Default for Android Search?

If you use Android search a lot you will have noticed that you write the same lines of code again and again. You have to configure two things to make Android’s search work:

  • the meta-data to use for search and
  • which Activity to use for search

Coming from the Java EE world, this reminds me of the state there a few years ago. Tedious XML files had to be edited – and they had to be way too verbose. But then the Java EE world moved gradually to convention by default. You just use XML for what isn’t part of the code or isn’t covered by reasonable defaults anyway. That’s what I would like to see for Android as well.

Android’s search configuration could also be replaced by meaningful defaults, so that some unnecessary definitions could be left out. Let me explain what I hope the Android developers will implement one day:

Configuration by default for the search configuration file

For your search activity you have to state where the configuration file can be found. You do this in your AndroidManifest.xml file:

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

Most often Android developers name the search configuration file searchable.xml and store it within the res/xml folder. Shouldn’t it be reasonable to assume that this is the case unless stated otherwise?

Actually there is only one reason why you should ever have to stray from this default: That is when you need two or more different search configurations within one project. Which should be very rare. In this case there is no way around using the <android:meta> element for both configurations. But only then.

Configuration by default for the search activity

Another information that you must add to your AndroidManifest.xml file is the definition of the search activity to use. This is done like this for the default search activity of your app:

<meta-data
      android:name="android.app.default_searchable"
      android:value=".SampleSearchActivity" />

But configuring the search activity in most cases is also superfluous. Most often the search is global for a project. So why not assume that this is the default. So if the AndroidManifest.xml file contains exactly one activity that has an intent filter for the action android.action.SEARCH this activity should be the global default for search. If more than one activity with the intent filter exists or if you want to use search only for certain activities you still can configure this by hand.

Probably another attribute is needed if you want to use the default, but want to exclude one activity from search. A possible solution could be

<meta-data android:name="android.app.not_searchable" 
           android:value="true" />

Granted: Both snippets are not that much code. But anything that is not necessary should be left out. It could be a source of error – and also of frustration.

To be fair: There are reasonable default values for most keys in the search configuration file. So this file can be kept to a minimum. Configuration by default would just be the next logical step.

Are there other configuration files or entries, you think that are superfluous and could be replaced by freasonable defaults? And what else could be optimized? Let us know in the comments – and if you have posted issues, please add a link to them. Thanks!

Share this article:

You can leave a response, or trackback from your own site.

2 Responses to “Why is There no Configuration by Default for Android Search?”

  1. Depesh says:

    it shows my app in google quick search box .
    By by default it is unchecked as searchale item and others are checked
    reason ?

    • That’s by design. Unless the user explicitly enables the app to be searchable, it won’t be. That’s true for all apps and there is no way to get around this. All enabled apps are either pre-installed ones that were enabled by the device vendor or were enabled by the user (in this case by you).

Leave a Reply

You can also subscribe without commenting.

Subscribe to RSS Feed My G+-Profile Follow me on Twitter!