idan idan - 1 year ago 92
Android Question

intent from library project to main project

When i try to pass from the main project to library project using intent it works fine but..... when i try to pass from the library project to the main project, it doesn't recognize the class in the main project.

i try to write in my library project this intent :

Intent intent = new Intent(this,com.example.uploadvideo.class);

i add to the manifests of both the main project and library project the two activities that i want to connect.

enter image description here


The library project does not know about the main project. The prefered solution imo would be to use an action rather than trying to load the class directly in the intent. This will also give you more flexibility if you want to re-use the library.

So the library would do

Intent intent = new Intent("com.example.action_video_upload");
intent.setPackage(mContext.getPackageName()); // only deliver to host app

and the main project would register for that intent in the manifest with

<intent-filter . . . >
    <action android:name="com.example.action_video_upload" />

More information can be found here: