Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android broadcast receivers vs aidl

What are the pros and cons of using aidl vs broadcast receivers for sending messages between apps (for both background and foreground handling)? I've been using receivers which is nice due to the subscription model with intent filters, and the ease of use / extensibility. Are there drawbacks to using this approach to vs AIDL?

Thx Ben

like image 959
Ben Avatar asked Jun 01 '12 04:06

Ben


1 Answers

BroadcastReceiver

  • It is an Asynchronous communication.
  • Complexity is low- It is the easiest way to communicate between processes.
  • One to All communication- A broadcast is transferring a message to all recipients simultaneously.
  • Android OS intent based communication between application components.
  • BroadcastReceiver.onReceive always run in the main thread(UI thread)
  • When sending data via an intent, you should be careful to limit the data size to a few KB. Sending too much data can cause the system to throw a TransactionTooLargeException exception. https://developer.android.com/guide/components/activities/parcelables-and-bundles

    The statements that Intents could transfer up to 1Mb worth of data are definitely wrong, 500Kb is more accurate. https://www.neotechsoftware.com/blog/android-intent-size-limit"

  • Security: A broadcast is transmitted across the Android OS and that could introduce a security threat.Other apps can listen to broadcasts. Any sensitive data should not be broadcasted.

AIDL

  • It is Synchronous and Asynchronous inter process communication. By default,the AIDL communication is synchronous. In order to make AIDL communication asynchronous, use “oneway” keyword.

  • Complexity is high - AIDL interface sends simultaneous requests to the service, which must handle multi-threading.

  • One to One communication

  • Using the underlying Android OS Binder framework

  • Requires writing thread-safe code.

  • The Binder transaction buffer has a limited fixed size, currently 1Mb, which is shared by all transactions in progress for the process. https://developer.android.com/reference/android/os/TransactionTooLargeException.html"

  • Security: AIDL is allows developers to expose their interfaces to other application. Both the client and service agree upon in order to communicate with each other.

like image 144
Rajesh P Avatar answered Sep 21 '22 20:09

Rajesh P