8
votes

In my android app I use a library project and I use one of it's activities. However in the library project that activity has MAIN action and LAUNCHER category intent-filter. So I added that activity to my manifest and removed the intent-filter. The manifests seem to be correctly merged into build/intermediates/manifests/full/debug/AndroidManifest.xml, and the activity looks as expected (without the intent-filter):

    <activity
        android:name="com.michaelrnovak.util.logger.Logger"
        android:configChanges="orientation"
        android:label="@string/show_log" >
    </activity>

However when I start the app from AndroidStudio in the emulator, then instead of my AlertsActivity, the library's Logger activity is launched. What am I doing wrong?

This is the manifest of the library:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.michaelrnovak.util.logger"
      android:versionCode="8"
      android:versionName="1.5">
    <uses-permission android:name="android.permission.READ_LOGS" />
    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity android:name=".Logger"
                  android:label="@string/app_name"
                  android:configChanges="orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="7" />
</manifest> 

and my app's manifest has the following relevant activity definitions:

    <activity
        android:name=".AlertsActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:launchMode="singleTop" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />          </intent-filter>
    </activity>
    <activity android:name="com.michaelrnovak.util.logger.Logger"
        android:label="@string/show_log"
        android:configChanges="orientation"
        tools:replace="android:label"
        >
        <intent-filter tools:node="removeAll" />
    </activity>
2

2 Answers

14
votes

Have you tried tools:node="remove" on the category node only? From my experience, it seems to work.

Something like this:

<activity android:name="com.michaelrnovak.util.logger.Logger"
        android:label="@string/show_log"
        android:configChanges="orientation"
        tools:replace="android:label"
        >
        <intent-filter>
            <category   tools:node="remove" android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
0
votes

I tried many ways on similar situation like you. I figured out that I must add tools:node="replace" in the Activity node to remove intent-filter's specific action and category. Try this :)

<activity 
    android:name="com.michaelrnovak.util.logger.Logger"
    android:label="@string/show_log"
    android:configChanges="orientation"
    tools:replace="android:label"
    tools:node="replace">

    <!-- Rewrite the intent-filter you want -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>