多个Android应用程序可以共享一个进程和应用程序上下文吗? [英] Can multiple Android applications share a single process and application context?

查看:377
本文介绍了多个Android应用程序可以共享一个进程和应用程序上下文吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在多个应用程序的应用程序上下文中共享一个单例?每个应用程序都将使用其自己的APK,但这听起来像是糟糕的体系结构,但请先听我说.

I am wondering if I could share a singleton on the application context across multiple applications? Each application would be in its own APK but This might sound like bad architecture but hear me out first.

之所以要这样做,是因为我有一个现有的库,该库通过蓝牙控制外部设备.该库是Java,但在后台却隐藏了全部由Java包装的本机(c/c ++).我曾经考虑过将所有这些都投入服务,但是IPC(我正在使用aidl)变得非常麻烦.试图将对象简化为基元几乎是不可能的(私有字段,jni指针等),并且尝试用AIDL包装所有内容非常混乱.

The reason I would like to do this is because I have an existing library which controls an external device over bluetooth. The library is java but under the covers there is allot of native (c/c++) all wrapped by java. I have looked at putting this all in a service but the IPC (I was using aidl) becomes very cumbersome fast. Trying to reduce object to primitives is next to impossible (private fields, jni pointers etc) and trying to wrap everything with AIDL is very messy.

如果每个应用程序都可以在相同的进程中运行,并且具有相同的应用程序上下文,因此允许我在该位置保留一个单例对象,这将使事情变得容易得多.我的古格夫使我不及格.也许不可能吗?

If each app could run in the same process and also have the same application context hence allowing me to keep a singleton object on there that would make things much easier. My googl-fu is failing me on this one. Maybe its not possible?

推荐答案

是的,他们可以.您只需在两个应用程序中为android:sharedUserIdandroid:process分配相同的值,并使用相同的证书对其进行签名.

Yes, they can. You just need to assign same values to android:sharedUserId and android:process in both applications and sign them with same certificate.

相关链接:

  • manifest property android:sharedUserId
  • application property: android:process
  • Processes and Threads General Description

这篇关于多个Android应用程序可以共享一个进程和应用程序上下文吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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