0

I have simple application in which I want to use component of library project that I imported.

I merged the manifest of library and main project by adding manifestmerger.enabled=true in project.properties so that I can use components of library project into main project.

But when I tried to start activity of library project from main project with the code below:

    Intent intent = new Intent(MainActivity.this, ScanActivity.class);
    intent.putExtra("scanType", REGISTER_BARCODE);
    startActivity(intent);

I got the following errors

02-20 01:51:46.524: E/AndroidRuntime(23675): FATAL EXCEPTION: main
02-20 01:51:46.524: E/AndroidRuntime(23675): Process: com.example.smartdna_l1, PID: 23675
02-20 01:51:46.524: E/AndroidRuntime(23675): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.smartdna_l1/com.linksmart.smartdna6.ScanActivity}; have you declared this activity in your AndroidManifest.xml?

-

{com.example.smartdna_l1/com.linksmart.smartdna6.ScanActivity}

Where com.example.smartdna_l1 is main project package and com.linksmart.smartdna6.ScanActivity is library project path.

The path which got detected is wrong.

Now my question is that how to avoid merging of path so appropriate activity path can be detected correctly to start the activity.

Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57
pkverma
  • 21
  • 4
  • Did you create both the library and app projects in Android Studio? Can you provide the directory structure of these projects and the AndroidManifest.xml files for each? – Code-Apprentice Feb 19 '16 at 23:09
  • No, I am working with Eclipse not android studio... @Code-Apprentice – pkverma Feb 20 '16 at 05:09

1 Answers1

-1

Try this:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("packagename//com.linksmart.smartdna6", 
                                     "classname//com.linksmart.smartdna6.ScanActivity"));
intent.putExtra("scanType", REGISTER_BARCODE);
startActivity(intent);

Make sure that in your library you've declared ScanActivity in library AndroidManifest.xml

For more info check Using an Android library project Activity within another project

Hope this helps!

Community
  • 1
  • 1
Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57