How can I launch an Activity from another Application Module within the same project?
I am not talking about how to open an Activity from another application, therefore this is not a duplicate of Launch an application from another application on Android
I have 2 modules: mobile and tv. Both are com.android.application
on their build.gradle
files and both are on the same package com.example.myapp
.
I want the tv module to launch the MainActivity of the mobile module.
I've added the following line to my build.gradle(tv) file:
compile project(path: ':mobile')
on MainTvActivity.java I tried to reference the MainActivity
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
which didn't work, because it couldn't resolve the symbol MainActivity. It won't even build.
The other attempt was to use intent filters:
on AndroidManifest.xml(mobile)
<activity
android:name="com.example.myapp.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.example.myapp.mobile" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
on MainTvActivity.java:
Intent intent = new Intent("com.example.myapp.mobile");
startActivity(intent);
which will build and install but will crash because it won't find anything to resolve the intent. However, if I install the mobile version and then run the tv one, it will work (as expected).