[英]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在编译时不会显示任何错误。
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:
一些解释可以在这里找到:
Why use the new Android feature plugin over the library plugin? 为什么要在库插件上使用新的Android功能插件?
Android: Can you add activities to the Instant App module? Android:您可以将活动添加到Instant App模块中吗?
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.