简体   繁体   中英

how to communicate in multi module dynamice feature Application

I have project structure like

app:

InstantApp:

library:

dynamic-feature1:

dynamic-feature2:

dynamic-feature3:

Now there is some dependency between dynamic-feature1 and dynamic-feature2. Now if i add it as dependency in dynamic-feature2 build.gradle then it will cause cyclic dependency. Above is just one example there are many other cases too. How to handle such dependency conflicts properly or any suggestion?

Communicate from the main app module to a dynamic feature module

You can do this by reflection in Java. Make sure your class and method names are not obfuscated in the dynamic modules.

Get a Fragment/Activity or other class from module:

method.invoke(objectYouWantToInvokeTheMethodOn);

Get a method from your class:

 Method method = class.getMethod("GenerateQuestion");

Invoke the method:

 method.invoke(objectYouWantToInvokeTheMethodOn);

Communicate from dynamic feature module to main module

To get a parent activity of a dynamic feature module's fragment you can do:

 @Override public void onAttach(Context context) { super.onAttach(context); activity = (Activity) context; }

Then you can call a method on that activity.

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