23

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.
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
androidTesting
  • 231
  • 1
  • 2
  • 3
  • Do you want build a chat like app? – Harry Joy Jan 09 '11 at 11:51
  • no, the apps should communicate with each other, the activities in app B should do things like vibrate, change the light and so on, and if for example vibrating is started, app B sends a result string like ("vibrate successful") to app A (app a is going to do much more later, but for this example i only need to communicated between this two apps) – androidTesting Jan 09 '11 at 12:17
  • I really need to same logic i try to use Remote Service can you check my question ? https://stackoverflow.com/questions/64478498/how-to-send-remote-service-message-onclick-via-messenger – saulyasar Oct 22 '20 at 14:15

1 Answers1

40

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Let's say we have an app that needs to know if 5 other apps have a specific file in their data folder. What's the best mechanism to use so that the first app can send a message and receive a "yes" result string or true boolean from the first app that has the file? – trusktr Jan 13 '13 at 00:38
  • About first option using `ResultReceiver` when I try to get result receiver parcelable from intent in my second application I got: `E/Parcel: Class not found when unmarshalling: com.myapp.demo.DemoActivity$1` Is there some tricky part? – L3K0V Jan 28 '16 at 16:28
  • @L3K0V: I recommend that you ask a separate Stack Overflow question, where you can provide a minimal, complete, and verifiable example of your problem, which would include the Java stack trace and the code that the trace refers to. – CommonsWare Jan 28 '16 at 16:29
  • @CommonsWare can you take a look please? http://stackoverflow.com/q/35067178/1274974 – L3K0V Jan 28 '16 at 16:47
  • Hi @CommonsWare can you check my question ? https://stackoverflow.com/questions/64478498/how-to-send-remote-service-message-onclick-via-messenger – saulyasar Oct 22 '20 at 14:16