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 t
You don't need to explicitly add activity in your main project's manifest if you have already added the activity in your library's manifest by using the following code when starting library's activity.
For Kotlin
val myIntent = Intent(activityContext, ActivityToLaunch::class.java)
// Needed to set component to remove explicit activity entry in application's manifest
myIntent.component = ComponentName(activityContext, PickerActivity::class.java)
activityContext.startActivity(myIntent, PICKER_REQUEST_CODE)
For Java
Intent myIntent = new Intent(activityContext, PickerActivity.class);
// Needed to set component to remove explicit activity entry in application's manifest
final ComponentName component = new ComponentName(activityContext, PickerActivity.class);
myIntent.setComponent(component);
activityContext.startActivity(myIntent, REQUEST_CODE);
you should import just the code of the activity ( not the manifest too ) , and then , declare your Activity ( of the library ) , in the manifest of your second project
did you add to the manifest?
http://developer.android.com/guide/topics/manifest/uses-library-element.html
I am aware that the question is quite old but I think this might help people like me that came up with the same problem.
Using Eclipse, the best way to share code and activities among libraries is probably the one that can be found in the android documentation here:
Managing Projects from Eclipse with ADT
This works:
In your library, put your custom Activity
:
public class MyLibraryActivity extends ListActivity { ... }
No need to put it into a manifest. In your calling Android project, create an empty (dummy) wrapper:
public class MyActivity extends MyLibraryActivity { }
and add reference to this class to your manifest:
<activity android:name="my_package.MyActivity" ... />
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.