Android Remote methods (AIDL) vs Intents - performance & battery usage
Asked Answered
H

3

6

My team is working on an Android project which consists of several Android applications which exchange data (on the same phone). The idea is to have several applications which are collecting some data and send this data to the main application. The main challenge here is to do the exchange as cheap as possible in terms of CPU load & battery usage.

As far as I know, there are two ways to achieve inter-process communications:

  1. Intents & activities - one activity catches the intents of another
  2. Remote methods (through AIDL)

I wonder which of these is more efficient in the following scenarios:

  1. Very frequent messages/method calls with very little data sent/traffic (e.g. just passing a bunch of primitives)
  2. Less frequent messages/method calls with large traffic chunks (e.g. collect data and periodically send a few KB/MB of data)
  3. Very frequent messages/method calls with large data chunks exchanged

I would appreciate any help, either in terms of comparison or a reference/link to a benchmark.

Heckman answered 16/2, 2011 at 11:0 Comment(1)
To your list of options for inter-process communication you should also add ContentProvider. It is also efficient way to share centralized data (all read and all may write) among several applications.Osteopathy
Q
2

I think for 1) you'd be best with a remote service and for 2) and 3) you'd be better off writing to files or a database. Intents are more for infrequent interprocess communication and starting apps and services.

Quillon answered 16/2, 2011 at 12:37 Comment(3)
Thanks. What about ContenProvider that Zelimir mentioned?Heckman
Are the applications in the same package? If so, you can just use a database directly. If they're not a ContentProvider is the right way to go :)Quillon
How expensive is using that database for temporary data such as passing some data from one method to another?Heckman
W
1

You could also try to use native code to create a shared memory as an alternative option. Check out this link for details: http://www.androidenea.com/2010/03/share-memory-using-ashmem-and-binder-in.html

Whore answered 16/2, 2011 at 13:25 Comment(0)
B
1

I suggest you use the Unix domain sockets mechanism to address scenario 3). The high frequency will make the use of files/databases complicated, and according to this answer, using Android's IPC is not recommended performance wise, since every object has to be converted to (and back from) a Parcel which takes time.. You can also use Unix pipes but it has some restrictions:

Basra answered 12/8, 2013 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.