Here's the scenario : I have 2 modules (In Android Studio, File -> New -> New Module) in my single application.
Module A (Its not a library project. it's gradle starts with apply plugin: 'com.android.application').
Module B (which is also not a library module).
Inside module B, I need to invoke an Activity (say MainActivity) which belongs to module A.
Module A manifest :
<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 manifest :
<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 it?
Please note that I cannot add module A's dependency in module B, since module A is not a library module.
Awaiting your valuable response.
If both application have the same signature (meaning that both APPS are yours and signed with the same key), you can call your other app activity as follows: Intent LaunchIntent = getActivity(). getPackageManager(). getLaunchIntentForPackage(CALC_PACKAGE_NAME); startActivity(LaunchIntent);
There are two ways to communicate between Modules in Android: Using Callbacks/ Interfaces. Using Local Broadcast.
To start an activity, call startActivity() and pass it your Intent . The system receives this call and starts an instance of the Activity specified by the Intent .
To launch any Activity
from any application, you can just do this:
Intent intent = new Intent();
intent.setClassName("packageName", "className");
startActivity(intent);
You don't need to be able to reference the source code of that Activity
during compile time.
This will solve your stated problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With