简体   繁体   English

我如何从另一个功能模块访问活动

[英]How can i access an activity from another feature module

I am creating an instant app, which include application module, base feature module, instant app module and an another feature module. 我正在创建一个即时应用程序,其中包括应用程序模块,基本功能模块,即时应用程序模块和另一个功能模块。 Problem is i am not able to access the activities of application module from base-feature and feature module and same between base-feature module and feature module but i am able to access activity of base-feature module from application module. 问题是我无法从基本功能和功能模块访问应用程序模块的活动,而基本功能模块和功能模块之间的访问相同,但是我能够从应用程序模块访问基本功能模块的活动。

Right now i am accessing the activities using : 现在,我正在使用以下方式访问活动:

Intent i = new Intent(this,
                    Class.forName("com.demo.test.appmodule.TextActivity"));

by this method studio don't show me any errors at compile time. 通过这种方法,studio在编译时不会显示任何错误。

  1. Is there any other way for communication between two different feature modules? 两个不同功能模块之间是否还有其他通信方式?
  2. Why i am able to access base-feature module activity from application module but not vice versa? 为什么我能够从应用程序模块访问基本功能模块的活动,反之亦然?
  3. can we access activities of application module from base or any other feature module? 我们可以从基础模块或任何其他功能模块访问应用程序模块的活动吗?

项目结构

在此处输入图片说明

Can i have a link which define the project structure for an instant app 我可以提供一个链接来定义即时应用程序的项目结构吗

Thanks in advance 提前致谢

The reason why you can't communicate directly between features is because they're independent from one another. 之所以不能在要素之间直接进行通信,是因为它们彼此独立。

The correct way to handle this is calling it with its URL, example: android-instant-apps/hello-feature-module/HelloActivity.java 处理此问题的正确方法是使用其URL进行调用,例如: android-instant-apps / hello-feature-module / HelloActivity.java

Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://hello-feature.instantappsample.com/goodbye"));
intent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivity(intent);

In an instant-app structure, the base acts as a library for the feature modules, and the features are built into APKs . 在即时应用程序结构中, 基础充当功能模块的库 ,功能内置于APK中 In an installed-app structure, both the base and features act as libraries for the application module. 在已安装的应用程序结构中, 基础和功能均充当应用程序模块的 Some explanation can be found here: 一些解释可以在这里找到:

There used to be a page @ https://g.co/instantapps that explained the structure of instant apps, but looks like it's missing. 曾经有一个页面@ https://g.co/instantapps解释了即时应用程序的结构,但看起来好像丢失了。 However, you can take a look at: 但是,您可以看一下:

And no, you won't be able to directly access activities of the application from a feature. 不,您将无法直接从功能访问应用程序的活动。 As an installed-app, com.android.feature modules are compiled/behave as com.android.library modules, so apply the same rules here: the application depends on the library, not the other way around. 作为已安装的应用程序, com.android.feature模块像com.android.library模块一样被编译/运行,因此在此处应用相同的规则:应用程序依赖于库,而不是相反。 To traverse that direction, you will need to use the same kind of Intent as shown above. 要遍历该方向,您将需要使用与上面所示相同的Intent。

Anything in com.android.application will be isolated from the feature modules of the instant-app, and will only appear in the installed-app. com.android.application都将与Instant-app的功能模块隔离开来,并且只会显示在已安装的App中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从另一个活动访问活动的视图 - How can I access a view of an activity from another activity 我如何从另一个活动访问片段方法 - How can I get access to a fragment method from another activity 如何使用Intent从另一个活动访问方法? - How can I use Intent to access a method from another activity? 如何从活动中访问方法并将其用于Android中的另一个活动? - How can I access a method from an activity and use it into another activity in Android? 如何从Android中的另一个活动访问一个活动中的组件(例如时间选择器)? - How can I access a component(for example a timepicker) in one activity from another activity in Android? 如何将图像从活动传递到Android中的另一个活动? - How can I pass an image from an activity to another activity in Android? 我如何从android中的另一个活动调用活动中的函数? - How can i call a function in activity from another activity in android? 如何在Android应用程序中全局访问另一个班级的活动? - How can I access an Activity from another class globally in an Android app? 如何从活动中的另一个 XML 文件访问视图 - How do I access a view from another XML File in an activity 如何从另一个模块调用活动 - How to call an activity from another module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM