Reputation: 65
I am trying to send an intent from an activity in library module to the activity in main app .But unable to send as the library module cannot have dependency on the main application resulting in circular dependencies. Is there any way to do this ?
Upvotes: 4
Views: 2144
Reputation: 3674
You don't need to reference to MainActivity
class name in library. Just add an intent-filter
to MainActivity
in your main app manifest:
<activity
android:name=".MainActivity">
<intent-filter>
<action android:name="com.example.main.mainactivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And in your library just call this to open MainActivity
:
Intent intent = new Intent("com.example.main.mainactivity");
startActivity(intent);
Note: Defining intent-filter
for activity implicitly sets android:exported
to true
. It means that other apps can use a same intent to launch your activity. If it is an issue, use permissions to limit your activity.
Upvotes: 5