Android 中的重叠活动
我正在尝试在基于 Web 的应用程序框架(快速连接)中实现本机 MapView。现在整个框架由一个 Activity 组成(这是不可避免的,因为框架完全在 WebView 中运行应用程序的主体,并且框架解析对本机功能的 javascript 调用,例如声音和本机系统视图)。我意识到 MapView 是一个奇怪的野兽,因为它需要在 MapActivity 内部运行。
因此,这给我留下了两个选择,将运行框架的单个 Activity 转换为 MapActivity,添加操作内部 MapView 的方法(问题是我们希望将代码贡献回框架项目,并且系统对待 MapActivity 的方式与普通 Activity 不同,导致所有非地图应用程序消耗比必要更多的资源),或者以某种方式将 MapActivity 覆盖在运行 WebView 的主 Activity 之上,主 Activity 通过以下方式与 MapActivity 进行通信:意图。
我完全意识到覆盖 Activity 与 Android 应用程序的设计完全矛盾,但我想知道这是否可能。我研究过 ActivityGroups,但找不到任何同时在屏幕上显示两个 Activity 的自定义 ActivityGroup 示例,更不用说重叠了。
tl;dr:在 Android 中实现重叠的 Activity 是可能的吗?我该怎么做?
I'm trying to implement a native MapView inside a web-based application framework (quickconnect). Right now the entire framework consists of one Activity (this is unavoidable, as the framework runs the body of the app entirely in a WebView, and the framework parses javascript calls to native functionality, such as sound and native system views). What I've realized is that MapView is an odd beast in that it needs to be run inside of a MapActivity.
So this leaves me with two options, convert the single Activity that runs the framework into a MapActivity, adding methods to manipulate the MapView inside (the issue with this is that we're looking to contribute the code back to the framework project, and the system treats MapActivities differently than normal Activities, causing all non-map apps to use up more resources than necessary), or somehow overlaying the MapActivity on top of the main Activity, which is running the WebView, with the main activity communicating with the MapActivity via Intents.
I fully realize that overlaying Activities is a complete contradiction to the design of Android apps, but I am wondering if it's possible. I've looked into ActivityGroups, and I can't find any examples of a custom ActivityGroup that shows two Activities on the screen at the same time, nevermind overlapping.
tl;dr: Is implementing overlapping Activities possible in Android, and how do I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前尚不清楚您的目标将如何实际实现。假设您确实有“重叠的活动”。然后呢?你得到了什么?第一个活动中的 JavaScript 代码无法对第二个活动执行任何操作。您必须在
MapActivity
中为MapActivity
实现 100% 的业务逻辑。由于无论如何您都必须教“quickconnect”如何调用startActivity()
,因此只需在 Java 中将您的地图实现为常规MapActivity
,然后就可以完成它。OTOH,如果您的目标是让支持 QuickConnect 的 JavaScript 代码来管理 MapView,那么您别无选择,只能重构整个 QuickConnect 以使用组合而不是继承,因此 QuickConnect 引擎可以在
Activity
或MapActivity
内部使用。无论如何,从长远来看,这可能是必要的,因为FragmentActivity
对于在 Android 兼容性库中使用片段是必要的,并且人们可能会认为 Quickconnect 应该使用片段提供平板电脑和电视支持。It is unclear how your objective will actually work. Let's suppose you do have "overlapping Activities". Then what? What have you gained? It's not like the JavaScript code from the first activity can do anything with the second activity. You're going to have to implement 100% of your business logic for the
MapActivity
in theMapActivity
. Since you are going to have to teach "quickconnect" how to callstartActivity()
regardless, just implement your map as a regularMapActivity
, in Java, and be done with it.If, OTOH, your objective is for quickconnect-supported JavaScript code to manage the
MapView
, then you have no choice but to refactor the whole of quickconnect to use composition rather than inheritance, so the quickconnect engine can be used inside anActivity
or aMapActivity
. That may prove necessary over the long haul anyway, sinceFragmentActivity
is necessary for using fragments in the Android Compatibility Library, and one might imagine that quickconnect should provide tablet and TV support using fragments.