0

Assumptions is that I can make changes to both app if needed. Two app do not invoke any Activity, its just sharing some metadata

As of now some options I can think of are:

  1. Using PackageInfo to find data about App B package name and find if its installed, its version name Then use ActivityManager.getRunningAppProcesses and check if its has App B process to know if its running.

  2. Set up content providers in two apps that provide data such as app version and fact we can access the provider we know its running and installed

  3. Setup broadcast receivers in two apps send intent to broadcast receiver and pass a reply back intent (I see its always async and thus doesn't fit my needs, am I missing some info that can make sending response back from App A -> App B in sync ?? )

  4. One can use SharedPreferences, (This isn't best way for me since I want it on demand and not be present if app is stopped or uninstalled )

Marco Acierno
  • 14,682
  • 8
  • 43
  • 53
aarati
  • 87
  • 8

1 Answers1

1

One can use SharedPreferences, (This isn't best way for me since I want it on demand and not be present if app is stopped or uninstalled )

This might work if you set the mode to Context.MODE_WORLD_READABLE but I wouldn't recommend it.

Setup broadcast receivers in two apps send intent to broadcast receiver and pass a reply back intent (I see its always async and thus doesn't fit my needs, am I missing some info that can make sending response back from App A -> App B in sync ?? )

I wouldn't recommend that. One should generally avoid situations like this and Intents weren't meant to be used that way. But for the record: there is a way to send Intents and receive results synchronously.

Set up content providers in two apps that provide data such as app version and fact we can access the provider we know its running and installed

This is kind of weird. Why would you use a ContentProvider to pass data between apps like this? It's essentially the same solution as with the SharedPreferences. I wouldn't recommend this.

Using PackageInfo to find data about App B package name and find if its installed, its version name Then use ActivityManager.getRunningAppProcesses and check if its has App B process to know if its running.

This really is the best option out of all those you listed. I don't understand why you hesitate to implement it this way? if the information you mentioned above really is all you need than you can get it all from PackageInfo and ActivityManager. This way the other app has to do nothing for this to work. The solution is solely implemented in the app which tries to obtain the data.


If you really want to pass bigger amounts or more complex data between apps then I would recommend you write a Service which the other app can bind to. You could also try AIDL.

You can also take a look at this answer by CommonsWare: android communication between two applications

Community
  • 1
  • 1
Xaver Kapeller
  • 49,491
  • 11
  • 98
  • 86
  • thanks for the link, the options mentioned are pretty much similar to what I have considered and these are mostly happening in async. In my scenario the data I am looking for is not user generated but is something already available with system. Thus i too am inclined to use the packageInfo. The only hesitation i have is because of the note on ActivityManager ** API Note: this method is only intended for debugging or implementing service management type user interfaces.** – aarati Jul 01 '14 at 17:52
  • @aarati: Checking to see whether the process is running is largely pointless, as processes come and go frequently. Just because a process happened to be running/not-running at the point you check says nothing about whether the process will be running/not-running a millisecond later. Using `PackageManager` to see if the app exists is reasonable, but whatever business problem you are trying to solve via `ActivityManager` can probably be solved more reliably in some other way. Also bear in mind that Google is locking down `ActivityManager` more, so your approach may stop working in the future. – CommonsWare Jul 01 '14 at 18:06