Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't open Activity from other module

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?

like image 358
EitanG Avatar asked Jul 30 '14 17:07

EitanG


People also ask

Can mainactivity call any activity from library module?

MainActivity can call any activity from library module. But you can't call MainActivity from library module. You can back to MainActivity via onBackPressed (). RK88 likes this. Thanks for your reply. Appreciate. Yes. I am talking about 2 Phone/Tablet Modules currently.

How to install multiple modules in Android Studio?

Download project, open in Android Studio 3.1, Start one module "app". Start another module aad_20180426a. Now both modules installed into device or emulator. Then click on FAB on any of module. You will switch between them back and force. 2. One module app and android library module

Why does the second activity start but the first starts empty?

If you run the app and tap the button on the first activity, the second activity starts but is empty. This is because the second activity uses the empty layout provided by the template. Figure 1.

What is the difference between app module and mainactivity module?

App module is master, library module is slave. MainActivity can call any activity from library module. But you can't call MainActivity from library module. You can back to MainActivity via onBackPressed (). RK88 likes this. Thanks for your reply.


Video Answer


2 Answers

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.

like image 52
arpit Avatar answered Sep 19 '22 10:09

arpit


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();
}
like image 28
Aman Kumar Avatar answered Sep 18 '22 10:09

Aman Kumar