Skip to content
Advertisement

How to call activity from a library module in android studio

I am trying to call an activity from a library module in my application. I keep getting the error

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.nextgis.mobile/com.nextgis.mobile.activity.MainActivity}; have you declared this activity in your AndroidManifest.xml?

I am calling the activity as

JavaScript

App manifest :

JavaScript

Library manifest :

JavaScript

I have added compile project(':gisapp') in the gradle file for the module app. I know gradle does manifest merging automatically but I could be wrong.

What am I doing wrong here ?

Note : This is the project which I am using as library.

Advertisement

Answer

We can use reflection to get class object.

Class.forName(“com.mypackage.myMainActivity”)

Add this code in Library project to call,

JavaScript

“com.mypackage.myMainActivity” is the Activity present in Main project, that we need to call from its Library project.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement