5

In my app I have the main activity defined in the manifest.xml file like this:

<activity
            android:name=".MainActivity"
            android:label="@string/guide_activity" >
            <intent-filter>
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.MAIN" />

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

when I run the project from eclipse connected to a real device or an emulator I receive the following message in the console: No Launcher activity found

what can be the reason of this ?

davioooh
  • 23,742
  • 39
  • 159
  • 250
Mina Wissa
  • 10,923
  • 13
  • 90
  • 158

1 Answers1

15

Split the intent-filter into two seperate ones. If you mix them like this, android won't determine that one of the two is the launcher filter.

<activity
    android:name=".MainActivity"
    android:label="@string/guide_activity" >

        <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>

        <meta-data android:name="android.app.searchable"
               android:resource="@xml/searchable"/>
</activity>
  • Thanks for the answer, it worked, but what is the reason for this, it's supposed to work without the need to split – Mina Wissa Feb 13 '12 at 11:05
  • 2
    When android sends an intent towards your app, it checks the intent filters to test if one matches all rules. Only when thats true, the intent will be actually delivered. In this case it checks whether the launch-intent will match both actions "SEARCH" and "MAIN". This is not the case, so the intent will not be delivered correctly. If you split it, the system sees that one intentfilter exists where all rules match and delivers the main intent properly. –  Feb 13 '12 at 11:10
  • Thanks, even I believe I never read this in the documentation, strange :) – Mina Wissa Feb 13 '12 at 11:14
  • 1
    It's poorly documented. Afaik in theory one filter can have in fact multiple actions according to the doc. It just doesn't work in the real world with mixed rules (only multiple actions seem ok) in my experience. The relevant documentation can be found under [Intents and Intent-Filter - Intent filters](http://developer.android.com/guide/topics/intents/intents-filters.html#ifs) *(4th paragraph under the intent filters subsection)*. –  Feb 13 '12 at 11:18