传入Android应用程序之间的类实例 [英] Passing class instances between applications in Android

查看:99
本文介绍了传入Android应用程序之间的类实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序App1定义A类和使用这个类的实例。我想实现的是 - 在安装后App1的设备上能够加载哪些App2的定义并实现了B类是A类的子类(从App1的包进口);并能够在App1的获得B类的一个实例。 B类不添加任何新的接口,因此以它为A级是确定的。但我不知道如何B类的实例传递给App1的(preferrably无需任何用户交互)。

I have an application App1 which defines class A and uses instances of this class. What I want to achieve is - after App1 is installed on the device to be able to load App2 which defines and implements class B which is subclass of class A (imported from App1 package); and be able to get an instance of class B in the App1. Class B doesn't add any new interfaces, so using it as class A is ok. But I am not sure how to pass the instance of class B to App1 (preferrably without any user interaction).

任何人都可以提出建议,如果这是可行的?

Can anyone advise if this is feasible?

推荐答案

从字面上看,这是不可能的。 App1和App2的将在不同的虚拟机上运行,​​可能在不同的进程。有没有办法传输它们之间的一个对象,任何比你更可以运输一个applet和JavaEE的服务器之间的Java对象。

Taken literally, it is impossible. App1 and App2 will be running on different virtual machines, probably in different processes. There is no way to transport an object between them, any more than you can transport a Java object between an applet and a JavaEE server.

您选择:


  1. 使用远程服务和AIDL实现远程过程调用,从而有效地使你的应用程序之间的按引用传递

  2. 使用 Parceable 意图演员,有效地为您提供应用程序之间的按值传递

  1. Use remote services and AIDL to implement a remote procedure call, effectively giving you "pass by reference" between apps
  2. Use Parceable and Intent extras, effectively giving you "pass by value" between apps

这篇关于传入Android应用程序之间的类实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆