Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Launch Activity in Android Library Module

To my Android app project, I added a module which contains an activity named "SampleDataMenuActivity". There is nothing special to this activity - it's added using the "New Module" -> "Android Library" dialog in Android Studio and includes the "Hello World" code generated by Android Studio.

The AndroidManifest.xml of the app includes (from the module):

<activity
    android:name="com.sample.sampledata.SampleDataMenuActivity" >
    <intent-filter>
        <action android:name="android.intent.action.SampleDataMenuActivity" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

In the build.gradle of the app:

dependencies {
    (...)
    compile project(':sampledata')
}

In the settings.gradle of the project:

include ':sampledata', ':app'

In the main activity of my app, I want to navigate to an activity in the module using:

startActivity(new Intent("com.sample.sampledata.SampleDataMenuActivity"));

The project builds just fine, but when I tap the button that should take me to the activity in the module it fails, reporting:

android.content.ActivityNoFoundException: No Activity found to handle Intent ( act=com.sample.sampledata.SampleDataMenuActivity )

What did I miss?

like image 873
jerry Avatar asked Nov 17 '14 16:11

jerry


1 Answers

I found the mistake, and perhaps I should remove the question. But as it was upvoted, somone else might be interested in this answer:

The manifest should state:

<activity
    android:name="com.sample.sampledata.SampleDataMenuActivity" >
    <intent-filter>
        <action android:name="com.sample.sampledata.SampleDataMenuActivity" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
like image 183
jerry Avatar answered Sep 22 '22 17:09

jerry