简体   繁体   中英

How can I call a class/method in main project from library project?

I have created two projects. One is a main application and second is just for the player.I am using player project as a library for the main project. Now, I have a feature in both project which allows users to share the video. I have done all sharing implementation and methods are in main project in a particular class called ShareActivity.class. Is there any way, I can use ShareActivity.class in Player library project?

I am thinking below solutions.

1) Should I use my library project as a jar file? Will it allow me to use a class from main project in library project?

2) Should I give reference of main project in a library project? I tried that but It is going in to infinite loop while building.

Please Advise!

You can use classes that are in a library project in your main project, but not the other way round. If both apps need a particular feature, move it to the library.

Instead of having an explicit Intent in your library project (with a reference to ShareActivity ), you could use an implicit Intent in your library project. Then your ShareActivity class would register to receive that implicit Intent . Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM