No Launcher activity found, despite being declared

2020-07-13 09:31发布

问题:

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 ?

回答1:

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>