I am trying to implement search in my application.
My application contain 4 activities and I want to add the search dialog only on 3 of them while only one of them (ProductsActivity) will be the default context.
unfortunately while I activate the search I keep getting the following error: "Key android.app.default_searchable expected String but value was a java.lang.Integer. The default value 开发者_如何学C was returned."
<activity android:label="@string/app_name" class=".AppEntry" android:name=".AppEntry">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".category.CategoriesListActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
</activity>
<activity android:name=".product.ProductsActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.default_searchable" android:resource="@xml/searchable"/>
</activity>
Any idea why ?
Thanks
For default searchable activity you have to put the meta-data tag under the application tag.
<application ... >
<meta-data android:name="android.app.default_searchable"
android:value=".DefaultSearchActivity"/>
<activity android:name=".ProductActivity" >
...
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivityForProducts"/>
</activity>
...
In that example the default application search will be done on the DefaultSearchActivity, while in the ProductActivity the search will be on SearchActivityForProducts. Hope it helps someone.
Shouldn't it be
<meta-data android:name="android.app.default_searchable"
android:value=".product.ProductsActivity"/>
instead of passing the @xml reference there again.
One thing really important here is to correctly name your activities as the Android guidelines explains http://developer.android.com/guide/topics/manifest/activity-element.html#nm
android:name The name of the class that implements the activity, a subclass of Activity. The attribute value should be a fully qualified class name (such as, "com.example.project.ExtracurricularActivity"). However, as a shorthand, if the first character of the name is a period (for example, ".ExtracurricularActivity"), it is appended to the package name specified in the element. Once you publish your application, you should not change this name (unless you've set android:exported="false").
There is no default. The name must be specified.
If you don't put the DOT in your activity name, your search action will only work on the activity you declared as "default_searchable". This little DOT cost us hours so be careful!
精彩评论