How to trigger an action (belonging to a module) in another module in Android?

Here's the scenario: I have 2 modules (in Android Studio, File → New → New Module) in one application.

  • Module a
  • Module B

Module A (its not a library project. It starts gradle with the use of the plugin: "com.android.application").

Module B (which is also not a library module).

Inside module B, I need to call an action (e.g. MainActivity) that belongs to module A.

Manifest module:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.abc.emergencycontacts"> <uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission> <uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true"> <activity android:name=".EmergencyContactsActivity" android:theme="@style/AppTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

Module B score:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.abc.secondaryactivity"> <application android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true"> <activity android:name=".BaseAppActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

How do I achieve this?

Please note that I cannot add the dependency of module A in module B, since module A is not a library module.

Awaiting your valuable reply.

+5
source share
1 answer

To run any Activity from any application, you can simply do this:

 Intent intent = new Intent(); intent.setClassName("packageName", "className"); startActivity(intent); 

You do not need to be able to reference the source code of this Activity at compile time.

This will solve your stated problem.

+1
source

Source: https://habr.com/ru/post/1260644/


All Articles