Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

android communication between two applications

I need some help in how to start developing two android applications (on one phone) which communicate with each other.

  1. Application A sends a string to application B.
  2. Application B receives the string for example "startClassOne", app B using a method starts classOne and gets the result. The result is sent back (again as string!) to Application A.
  3. Application A writes in the console the received string from B.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Hello, i need some help in how to start developing two android applications (on one phone) which communicate with each other.

On the whole, you generally don't want to artificially split one application into two, particularly if you are the author of both.

That being said, you can:

  • have Application B expose a an IntentService that will be called via startService() from Application A, with results passed back via a PendingIntent from createPendingResult() or a Messenger or a broadcast Intent or a ResultReceiver; or
  • have Application B expose a Service with an API defined in AIDL, and have Application A bind to that service, then have Application A call methods on Application B, or
  • send a broadcast Intent from Application A to Application B, with results being passed back by the same roster of options in the first bullet above, or
  • have Application B implement a content provider, and have Application A use ContentResolver to manipulate that content provider
  • and so on

Be sure work through all of the security ramifications of what you are doing, since you are exposing an API not only for Application A to use, but for any application on the device to use, unless you secure it with permissions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...