Android 上运行时动态链接/引用类
我想知道是否有一种简单而干净的方法来实现以下所需的功能:
我有一个主 APK,它提供了我的应用程序的核心功能,其中包含一个要扩展的抽象类。还有各种其他 APK,每个 APK 都包含抽象类的唯一子类,并重写其某些方法以提供扩展功能。当这些子类被实例化时,它们需要对其各自的 APK 中包含的资源进行解码。我选择将这些子类放在单独的 APK 中,以允许用户仅安装所需的组件,而无需修改主 APK,主 APK 将在启动时提供所有可用组件的列表。
我的主要问题:
有没有一种方法可以引用另一个 APK 中的类,而无需像我的子类试图完成的那样重复代码? 是否可以将实例化的子类引用或传递回我的主应用程序,在主应用程序中,仅使用原始抽象类的知识即可调用重写的方法?
谢谢。
I am wondering is there is a simple and clean way of achieving the desired functionality below:
I have a main APK that provides the core functionality of my application, which contains an abstract class to be extended. There are various other APKs, each containing a unique subclass of the abstract class and overriding some of its methods in order to provided extended functionality. When these subclasses are instantiated, they require decoding of resources contained in their respective APKs. I chose to have these subclasses in separate APKs to allow the user to install only the desired components without having to modify the main APK, which will provide a list of all available components on launch.
My main questions:
Is there a way to reference a class in another APK without duplicating code like my subclasses are trying to accomplish?
Is it possible to reference or pass the instantiated subclasses back to my main application where the overridden methods will be called with only knowledge of the original abstract class?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果所有 APK 都使用相同的证书进行签名,您可以使用此答案中概述的方法:
Android:如何在使用同一证书签名的项目之间共享代码
If all the APKs are signed with the same certificate, you can use the method outlined in this answer:
Android: how to share code between projects signed with the same certificate