How can i access an activity from another feature module

◇◆丶佛笑我妖孽 提交于 2019-12-02 09:29:41
TWL

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

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. 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. 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. To traverse that direction, you will need to use the same kind of Intent as shown above.

Anything in com.android.application will be isolated from the feature modules of the instant-app, and will only appear in the installed-app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!