How to send an intent From activity in the library module for the main activity of applications

I am trying to send an intention from activity in a library module to action in the main application. But it cannot be sent because the library module cannot have dependencies on the main application, which leads to cyclical dependencies. Is there any way to do this?

+4
source share
1 answer

You do not need to reference the class name MainActivityin the library. Just add intent-filterin MainActivityto your main application 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);

. intent-filter android:exported true. , . , , .

+5

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


All Articles