How to create a shared library in Android

前端 未结 2 1133
青春惊慌失措
青春惊慌失措 2021-01-11 14:01

I have a library, say LIB, which exposes the quite a few APIs and classes for use by application developers.

If there are more than one applications that use LIB on

2条回答
  •  梦谈多话
    2021-01-11 14:08

    Okay, after spending time on this, here the answers to my questions:-

    Q. How to make sure that there is only one instance of LIB ? - Only through exposing the LIB functionality through a service.

    Q. How to deploy LIB(separate apk/ bundled with every application that uses it, but only one of them creating the library instance at any point of time) etc. -

    For service, there would be a separate apk(or probably bundled with one of the service client app),

    Q. Is there any other way(other than service/AIDL) to make sure that only one instance of LIB runs irrespective of the number of applications using it.

    Yes, that would be like LIB is bundled with every application. But that would need a strong communication protocol between the libraries using intents, so that one of them acts as master, and shares the data with the other libraries. Effectively, the LIB packaged within an apk starts its engine, only if no other instance is running. One way of accomplishing this is using broadcasts and to maintain security, permissions can be associated with the involved broadcast actions.

提交回复
热议问题