Search code examples
androidbroadcastreceivershareandroid-library

Share data between Android app and library


I'm developing an Android library and an app. They are supposed to work together like that: the app hosts a String and has several other tasks. The library will be used by third party developers. They should be able to query the installed app (even if it's closed and without opening the GUI of the app) by implementing the library (which does other stuff too). My current solution for this are broadcasts:

  1. The library checks if the app is installed and if so, sends an explicit intent via braodcast (also secured by custom permission, although the shared String isn't even a secret).
  2. The app receives the broadcast and sends an answer broadcast back to the library.

Right now I'm not really shure if that's the best approach. So my question is:

Is there a better way to share simple data between an app and a library that can be used by many apps than using broadcasts?


Solution

  • You should use Content Providers.