As you can't have a compile time dependency of the dynamic feature module on the app module:
- You need to first ensure the module is installed:
Use the SplitInstallManager's, getInstalledModules() method and check that it exists.
Using reflection, create an instance of the Class which you want to call and call the different methods:
Class<?> dynamicFeatureClass = Class.forName("packagename.DFClass")
Constructor<?> cons = dynamicFeatureClass.getConstructor();
Object dynamicFeatureClassInstance = cons.newInstance();
Using reflection, you can call the different methods now.
- It would be better if you define a common interface in your base module and implement those methods in your dynamic feature class.
Then you can do:
FeatureContract feature = (FeatureContract) dynamicFeatureClassInstance;
// In the base module.
public interface FeatureContract
{
void performSomething();
}
// In the dynamic feature module.
DFClass implements FeatureContract
{
performSomething()
{
//code
}
//other Class methods
}
With this approach, you will only need to make a single reflection call to create an instance of your class in the dynamic feature module and after that you will be able to use the compile time benefits as you would be calling the methods using the interface.