开发者

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

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 appli开发者_如何学Pythoncations 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.


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.


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


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:

  • How to create named pipe (mkfifo) in Android?
  • https://groups.google.com/forum/#!topic/android-ndk/lD-V7Nxe5y4
  • How to use unix pipes in Android
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜