Question

I have two applications each with one activity in them, the first does this when you press a button:

final private static String START_APP_INTENT = "com.example.app1.START_APP2";
Intent intent = new Intent(START_APP_INTENT);
        startActivity(intent);

The second application has the following in its android manifest file:

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.app2.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="com.example.app1.START_APP2" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

When I press the button I get the following exception:

Caused by: android.content.ActivityNatFoundException: No Activity found to handle Intent { act=com.example.app1.START_APP2 }

My app2 has that intent filter. Why am I getting this exception?

Was it helpful?

Solution

Your <intent-filter> isn't correct. You have this:

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <action android:name="com.example.app1.START_APP2" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

You need this:

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <action android:name="com.example.app1.START_APP2" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>

The first filter is so that your app will show up in the list of available applications. The second filter is for use by the other application. When an application calls startActivity() and there is no explicit component specified in the Intent, Android automatically adds the DEFAULT category to the Intent. Since you haven't got the DEFAULT category in your <intent-filter>, it does not match and Android cannot find a suitable activity to start.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top