0

I am developing an android application and I want to split it in two separate downloadable store apps. The first will be the main one and the second will act as an addon.

Users will only need the addon in special cases and I don't want to force them to download data they will never use - they will get the addon from Store when they will need (the main application will request it when certain conditions are met).

My question is if Android permits the main application to call methods from the addon app in order to parse the result and display it and how can this be done.

I have looked over similar posts (Android - Build an application that supports add-ons) but it is not yet clear to me how this can be done. Until now, I have launched an activity with my intent, it executed as expected and returned the correct result, but I am intersted in having this done without the client to see it (both applications will act as a single one).

Community
  • 1
  • 1
Victor
  • 1,001
  • 2
  • 14
  • 25
  • 1
    what you are looking for is inter-application communication. This is usually done using broadcasts, content provider, or bound services (with messengers or AIDL), depending on what you actually need to do. – njzk2 Feb 18 '15 at 15:29
  • Thank you @njk2 . I have made a test with broadcast method you mentioned. I think I will go with this solution, even though it does not look very pretty - the flow as I can see is: broadcast a task, catch and process it in the addon application, then, from the addon, broadcast another task (this will be the result) for the main application. – Victor Feb 24 '15 at 16:08
  • bound services, with messengers or full-fledged AIDL are cleaner, but a bit more complex to setup. More maintainable, too, so you may want to take a look at that anyway. – njzk2 Feb 25 '15 at 04:17
  • @njzk2 , it is possible to use bound services with two different apps or it works only by using in the same app? Until now, all the examples I have read are referring to one app: [RemoteMessengerServiceSample](http://developer.android.com/reference/android/app/Service.html#RemoteMessengerServiceSample), [bound services](http://developer.android.com/guide/components/bound-services.html), or [this one](http://www.survivingwithandroid.com/2014/01/android-bound-service-ipc-with-messenger.html). – Victor Feb 25 '15 at 15:14
  • yes, as long as your service can be accessed by the other app. you can also share the aidl between the 2 apps. – njzk2 Mar 01 '15 at 19:00
  • @njzk2 First of all I am intersted if you have an example for bound services between different apps. Secondly, do you know if a broadcast receiver can be started without effectively starting the App ? I am asking this because now I am developing using the broadcasting scenario and it seems that the broadcast receiver from Addon App does not start listening if it did not have been launched at least one time. – Victor Mar 05 '15 at 08:16
  • I found a solution for the second part of my question (starting the broadcast receiver immediately after app installation): as [this link](http://www.javacodegeeks.com/2012/05/android-broadcast-receiver-change-in.html) is explaining, adding **FLAG_INCLUDE_STOPPED_PACKAGES** before sending the intent, will solve the problem (e.g. **intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);**). – Victor Mar 09 '15 at 09:03

1 Answers1

0

I have solved this as njzk2 suggested.

Briefly, the main app is sending a broadcast with an intent that contains the task it needs to be completed. The addon receiver intercepts the call, computes the result and after all the work is done it sends the response back to the main app the same way it received the task: by creating an intent containing the result and broadcasting it.

More info: in my case I needed to synchronize the calls (sending the task and waiting for the response). I did not find any library to do it automatically, so I made use of wait and notify. If someone else knows a better way, please share.

Victor
  • 1,001
  • 2
  • 14
  • 25