Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: how to declare an activity as main and searchable?

I would like my main activity to be searchable also but when I change the manifest.xml to

 <intent-filter>
       <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
       <!-- declare the default searchable Activity for the whole app -->
       <action android:name="android.intent.action.SEARCH" />            
 </intent-filter>

it cant find the main activity and the application doesn't run. any idea? is it not best practice to use the same activity as searchable also? Thanks, Alisa

like image 930
Alisa Avatar asked Apr 21 '11 04:04

Alisa


People also ask

How do I make activity default activity?

In Android, you can configure the starting activity (default activity) of your application via following “intent-filter” in “AndroidManifest. xml“. See following code snippet to configure a activity class “logoActivity” as the default activity.

What is main activity in Android?

Typically, one activity in an app is specified as the main activity, which is the first screen to appear when the user launches the app. Each activity can then start another activity in order to perform different actions.


1 Answers

You need to add a new intent-filter with the action.SEARCH

<activity
    android:name=".activities.YourActivity">
    <intent-filter>
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.MAIN" />
    </intent-filter>
     <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
    </intent-filter>
</activity>
like image 173
Maragues Avatar answered Nov 16 '22 02:11

Maragues