简体   繁体   English

从另一个充当插件的Android应用程序调用方法

[英]Call method from another Android app which is acting as an addon

I am developing an android application and I want to split it in two separate downloadable store apps. 我正在开发一个Android应用程序,我想将它拆分为两个单独的可下载商店应用程序。 The first will be the main one and the second will act as an addon . 第一个将是主要的 ,第二个将作为插件

Users will only need the addon in special cases and I don't want to force them to download data they will never use - they will get the addon from Store when they will need (the main application will request it when certain conditions are met). 用户在特殊情况下只需要插件,我不想强​​迫他们下载他们永远不会使用的数据 - 他们将在需要时从Store获取插件(主应用程序将在满足某些条件时请求它) 。

My question is if Android permits the main application to call methods from the addon app in order to parse the result and display it and how can this be done. 我的问题是,如果Android允许主应用程序从插件应用程序调用方法,以便解析结果并显示它,以及如何完成。

I have looked over similar posts ( Android - Build an application that supports add-ons ) but it is not yet clear to me how this can be done. 我查看了类似的帖子( Android - 构建支持附加组件的应用程序 ),但我还不清楚如何做到这一点。 Until now, I have launched an activity with my intent, it executed as expected and returned the correct result, but I am intersted in having this done without the client to see it (both applications will act as a single one). 到目前为止,我已经按照我的意图启动了一个活动,它按预期执行并返回了正确的结果,但是我很有兴趣在没有客户端看到它的情况下完成(两个应用程序将作为单个应用程序)。

I have solved this as njzk2 suggested. 我已经解决了这个问题,因为njzk2建议。

Briefly, the main app is sending a broadcast with an intent that contains the task it needs to be completed. 简而言之,主应用程序发送的广播的意图包含需要完成的任务。 The addon receiver intercepts the call, computes the result and after all the work is done it sends the response back to the main app the same way it received the task: by creating an intent containing the result and broadcasting it. 插件接收器拦截调用,计算结果,完成所有工作后,它以与接收任务相同的方式将响应发送回主应用程序:通过创建包含结果并传播结果的意图。

More info: in my case I needed to synchronize the calls (sending the task and waiting for the response). 更多信息:在我的情况下,我需要同步调用(发送任务和等待响应)。 I did not find any library to do it automatically, so I made use of wait and notify. 我没有找到任何库自动执行,所以我使用了wait并通知。 If someone else knows a better way, please share. 如果其他人知道更好的方式,请分享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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