Can't open Activity from other module
Asked Answered
C

3

7

I've added a reference to a new module and try to open an Activity from it. It throws an Exception that says:

android.content.ActivityNotFoundException: Unable to find explicit activity class{
com.giljulio.imagepicker.ui/com.giljulio.imagepicker.ui.ImagePickerActivity };

have you declared this activity in your AndroidManifest.xml?

Do I need to add anything else beside reference the new module?

Countermeasure answered 30/7, 2014 at 17:31 Comment(5)
Did you in fact add the activity to your AndroidManifest.xml?Teenager
You can check this. #16546225Disreputable
declare ImagePickerActivity activity in the Manifest... <activity android:name="com.giljulio.imagepicker.ui.ImagePickerActivity"/>Evangelineevangelism
Thanks. It was really not define in my AndroidManifest, But, maybe I don't understand something, I want to use a github project ( github.com/giljulio/android-multiple-image-picker ), If I import this module to my project I need to call it's main activity ? when I do so, it throw an exception that it doen not recognize some of it R.id's. the module manifest is : <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" > </application>Countermeasure
I investigated this issue in the following article and proposed a practical solution. https://mcmap.net/q/379348/-how-to-start-an-activity-in-another-module-explicitlyChilung
G
6

You have to define in gradle dependencies(in module where you want to call another module activity):

dependencies{
     ...
     compile project(':yourModuleName')
     ...
}

After adding this sync the gradle and now can you use the activity in the module.

Growing answered 25/5, 2015 at 9:43 Comment(1)
Do you edit the build.gradle file directly, or is there a dialog in Android Studio to use?Junk
F
2

User like this. This will help you

Intent intent = null;
try {
    intent = new Intent(this, 
       Class.forName("ir.test.testlibary1.HelloWorldActivity"));
    startActivity(intent);
} catch (ClassNotFoundException e) {
    e.printStackTrace();
}
Flaring answered 15/7, 2019 at 7:21 Comment(0)
G
0

Ok, so I am a few years late.

The issue is not that you don't have the gradle dependency as @arpit suggested, it seems you report a runtime exception. Also, what @Aman suggested will help with the handling the exception, it will just not help you start the activity.

If understood correctly, you have a multi-module app (let's say A-app module and B-lib module) and need to call another lib-module(C) from one B.

If that is the case, you need to declare that library's activity(C) in your module's(B) Manifest.xml, inside the tag.

If it has not already been setup, you also need to enable manifest merger.

Glosseme answered 23/10, 2020 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.