title: Android remote service callbacks
body: <p>(I have a <strong>remote</strong> service with an AIDL interface that is used by several client apps. I would like to add an asynchronous method to the interface for calls that take some time, but I need the solution to be <strong>secure</strong>, meaning that only my applications can communicate with the service. The client applications are signed with the same signature as the service app. Currently the apps just bind to the service and call a single interface method to perform various operations.</p>
  
  <p>One option is broadcasting an Intent from the service when the operation is complete and using a BroadcastReceiver in the client application, but (<strong>Question #1</strong>) can this be done in a way that ensures only my apps can receive the Intent? setPackage() seems to do this, but I need to support Gingerbread devices, which seems to rule out that approach according to the answer here: <a href="https://stackoverflow.com/questions/9370587/setpackage-for-intent-in-gingerbread">setPackage for intent in gingerbread</a></p>
  
  <p>So it seems I need to add a second .aidl interface with the callback interface for the service to use, implemented by the client. I have seen examples that use listeners here, but I am not sure what the difference is versus the client just passing in the second interface object as an argument (as used in the IScript / IScriptResult example from this answer: <a href="https://stackoverflow.com/questions/2026393/service-call-backs-to-activity-in-android">Service call backs to activity in android</a>)</p>
  
  <p><strong>Question #2</strong>, what is the benefit of using a listener here vs. a callback method?</p>