Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an Android library project Activity within another project

I have an Android library project that I would like to use from within another Android project.

The library has a Activity declared in its AndroidManifest. When I try the following within the second project:

        Intent intent = new Intent(this, ReaderActivity.class);
        startActivity(intent);

I get the following exception:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.digitalpages.reader.demo/br.com.digitalpages.reader.demo.ReaderDemoActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.digitalpages.reader.demo/br.com.digitalpages.reader.ReaderActivity}; have you declared this activity in your AndroidManifest.xml?
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
...
 Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.digitalpages.reader.demo/br.com.digitalpages.reader.ReaderActivity}; have you declared this activity in your AndroidManifest.xml?
     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
...

How can I open the Activity from the another project?

EDIT: By users answers I added the following line into my second project

<uses-library android:name="br.com.digitalpages.reader" android:required="true" />

But it's still doesn't works

like image 661
Marcos Vasconcelos Avatar asked May 27 '11 20:05

Marcos Vasconcelos


People also ask

What is lib in Android?

An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest.


3 Answers

I believe you must include the <activity> in your own AndroidManifest.xml -- I don't think it gets picked up from a library. I don't have my reference for that handy.

Update: It's official solution. From the doc:

Declaring library components in the manifest file

In the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project. For example, you must declare any <activity>, <service>, <receiver>, <provider>, and so on, as well as <permission>, <uses-library>, and similar elements.

Declarations should reference the library components by their fully-qualified package names, where appropriate.

like image 140
mah Avatar answered Sep 19 '22 00:09

mah


Intent intent = new Intent(android.content.Intent.ACTION_VIEW); intent.setComponent(new ComponentName("packagename//ex-com.hello",                                       "classname//ex-com.hello.ExampleActivity")); startActivity(intent); 

And make sure in library you have declared the activities. You don't need to declare the library activities in your current project's manifest.

like image 39
sheetal Avatar answered Sep 22 '22 00:09

sheetal


did you add to the manifest?

http://developer.android.com/guide/topics/manifest/uses-library-element.html

like image 20
Aleadam Avatar answered Sep 20 '22 00:09

Aleadam