如何在Android中创建共享库 [英] How to create a shared library in Android

查看:103
本文介绍了如何在Android中创建共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个库,例如LIB,它公开了许多API和类供应用程序开发人员使用。

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

如果有多个应用程序在使用在电话上的LIB,我只希望创建和运行一个LIB实例。它与Android平台服务(例如LocationManager,SensorManager,PackageManager等)有些相似。

If there are more than one applications that use LIB on the phone, I want only one instance of LIB to be created and running. It is somewhat similar to what Android Platform Services like LocationManager, SensorManager, PackageManager etc.

具体来说,有两个问题需要解决:-

Specifically, there are two problems that are to be addressed:-


  1. 如何确保只有一个LIB实例?

  2. 如何部署LIB(独立apk /捆绑每个使用它的应用程序,但只有一个在任何时间创建库实例)等。

  3. 还有其他方法(服务/ AIDL除外)来确保


推荐答案

好,花了一些时间后,在这里回答了我的问题:-

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

Q。如何确保只有一个LIB实例? -
仅通过通过服务公开LIB功能。

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

Q。如何部署LIB(与使用它的每个应用程序捆绑在一起的apk /,但是在任何时间点只有一个创建库实例),等等。-

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. -

服务,将有一个单独的apk(或可能与一个服务客户端应用捆绑在一起)

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

Q。是否有其他方法(服务/ AIDL除外)来确保仅运行一个LIB实例,而不管使用它的应用程序数量如何。

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.

是的,就像LIB与每个应用程序捆绑在一起一样。
但这需要在库之间使用意图进行强有力的通信协议,以便它们中的一个充当主节点,并与其他库共享数据。实际上,仅当没有其他实例在运行时,打包在apk中的LIB才会启动其引擎。实现此目的的一种方法是使用广播并维护安全性,可以将权限与所涉及的广播操作相关联。

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.

这篇关于如何在Android中创建共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆