Android:从外部 dex 加载活动
是否可以从外部 dex 文件加载活动?我正在考虑一些插件风格的架构,其中可以通过下载包含额外功能的活动和类的 dex 文件来扩展应用程序。
我已成功使用 DexClassLoader 和反射从下载的 dex 文件中加载并调用类上的方法。但是我可以以某种方式使用这种技术来下载并呈现活动吗?是否可以以编程方式注册这个新活动,以便我可以使用意图调用它?
我知道可以(推荐的方法是)使用 APK 通过正常过程安装其他 Activity,然后使用 Intents 从我的主 Activity 加载它,或者简单地更新已安装的应用程序,但我想扩展已安装的应用程序应用程序通过下载一些额外的类并在同一个虚拟机、同一个沙箱中执行所有内容。
嗯,如果您不明白我的意思,请告诉我,因为这有点混乱..:)
Is it possible to load activities from an external dex-file? I'm thinking of some plug-in style-architecture, where an application can be extended by downloading dex-files with activities and classes containing extra functionality.
I've managed to load and invoke methods on a class from a downloaded dex-file using DexClassLoader and reflection. But could I somehow use this technique to download and present an Activity? Is it possible to register this new Activity programmatically so that I can invoke it using an Intent?
I know that it's possible (and the recommended way is) to install the other Activity through the normal procedure with an APK, and then load it from my main activity using Intents or simply update the installed application, but I want to extend my already installed application by downloading some extra classes and execute everything in the same VM, same sandbox.
Hm, let me know if you don't understand what I mean, cause this got a bit messy.. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不完全是。活动必须在应用程序的清单中预先定义。
您可以尝试使用 JRuby 和 Ruboto 使用的方法,其中清单中的一项活动可以通过不同的实现重新调整用途。我还没有完全剖析他们的方法,但我的印象是他们的活动将事件转发到 JRuby 脚本。在您的情况下,活动会将事件转发到从 DEX 文件加载的其他类。
Not exactly. Activities must be pre-defined in the application's manifest.
You can try to use the approach that JRuby and Ruboto use, where there is one activity in the manifest that gets repurposed with different implementations. I haven't dissected their approach fully, but I am under the impression that their activity forwards events to a JRuby script. In your case, the activity would forward events to some other class loaded from the DEX file.