开发者

Passing class instances between applications in Android

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开发者_C百科 B to App1 (preferrably without any user interaction).

Can anyone advise if this is feasible?


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.

Your options:

  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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜