1

Is it possible to write an Android library that is used by two different android apps, but has a single instance on a device?

In a way, it would be a "singleton library" on device scope.

I.e. I would like to break an app into 3 pieces:

  • a client app
  • simple admin view app
  • a library, with core functionalities and database, that is been used by both apps.
daneejela
  • 13,081
  • 7
  • 38
  • 50
  • 3
    Only if you are the device manufacturer or firmware developer. For ordinary Android apps, each app contains a copy of every library that you include in the build process. More importantly, one app's data is independent of another app's data, and libraries themselves do not have data independent of the app using the library. – CommonsWare Jul 07 '19 at 13:39
  • @CommonsWare Thank you for your answer. Could desired behavior be achievable if I wrap the library into a background service that both apps can communicate with? – daneejela Jul 07 '19 at 14:32
  • 1
    You can have one app talk to another app via IPC, which can include binding to a service. You would wind up designating one app as being the primary app, the one that holds the data and exposes the service. The other app would be a secondary app, having little/no data of its own and talking to the primary app via that exposed service. This gets to be a bit tricky to secure, so that other apps do not use the primary app's exposed IPC API. – CommonsWare Jul 07 '19 at 14:37

0 Answers0