1

I'm experimenting, specifying my own action for use in an implicit intent. In a single package, I define two activities. ActivityTwo is to be called from onClick() in ActivityOne, using an implicit intent with an action "course.labs.activitylab.MY_ACTION". But I haven't been able to make it work.

In strings.xml:

<string name="myfunnystring">course.labs.activitylab.MY_ACTION</string>

In AndroidManifest.xml:

    <activity
        android:name=".ActivityTwo"
        android:label="@string/title_activity_activity_two" >
        <intent-filter>
            <action android:name="@string/myfunnystring" />
        </intent-filter>
    </activity>

In onClick() in the OnClickListener() in onCreate() in ActivityOne.java:

            Intent intent = new Intent();
            intent.setAction(getString(R.string.myfunnystring));
            intent.setFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
            startActivity(intent);

The program crashes in the emulator, and I find this in the logcat window:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=course.labs.activitylab.MY_ACTION flg=0x8 }

What am I doing wrong?

John Surname
  • 357
  • 1
  • 4
  • 8

1 Answers1

3

Add the default category to your intent filter.

<intent-filter>
    <action android:name="course.labs.activitylab.MY_ACTION" />
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
tachyonflux
  • 20,103
  • 7
  • 48
  • 67
  • I think you can't use a string resource in the action name. – tachyonflux May 25 '15 at 17:19
  • That fixes it. Okay, so I made two mistakes. I used a string resource in the action name in the filter. IDK why that shouldn't work, and if it won't work, IDK why it isn't detected at build-time. And I failed to give a category to the intent filter. Thank you, karaokyo. – John Surname May 25 '15 at 17:47
  • These two requirements are explained at http://developer.android.com/guide/components/intents-filters.html – John Surname May 25 '15 at 22:39