1

I have an activity which I declare in my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.my">
  <uses-sdk android:minSdkVersion="14"/>
  <application>
    <activity
        android:name="com.my.InternalDummyActivity"
        android:exported="false">
    </activity>
  </application>
</manifest>

I have tried without the exported=false as well

The application contains an inner library with another activity.

I try to call an explicit intent from the other activity (other namespace) But I always get an exception:

Intent intent1 = new Intent(activity.getApplicationContext(), InternalDummyActivity.class);
activity.startActivity(intent1);


ComponentName componentName2 =
    new ComponentName(
        "com.my","com.my.InternalDummyActivity");
Intent intent2 = new Intent().setComponent(componentName2); //dones work
activity.startActivity(intent2);


Process: com.comp.outter, PID: 9267
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.my/com.my.InternalDummyActivity}; have you declared this activity in your AndroidManifest.xml?

How can I fix this?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

2 Answers2

1

Try using one of the ComponentName's contructors that uses a Context, such as

ComponentName cn = new ComponentName(context,
"com.my.InternalDummyActivity");

For some reason, you can use the contructor taking two Strings only if you know the class dynamically.

Also, update your manifest as follow:

<activity
        android:name=".InternalDummyActivity">
</activity>

and application package name should be in lower case only, as mentioned in Java's Naming Conventions in Oracle Docs

Package names are written in all lower case to avoid conflict with the names of classes or interfaces

matdev
  • 4,115
  • 6
  • 35
  • 56
  • I have added my code of calling the explicit intent – Elad Benda Aug 13 '19 at 14:45
  • Try with this line in your manifest: android:name=".InternalDummyActivity"> – matdev Aug 13 '19 at 14:55
  • Why do you use the ComponentName to build your Intent ? Does the new Intent(activity.getApplicationContext(), InternalDummyActivity.class); method work ? – matdev Aug 13 '19 at 15:02
  • yes, it does. But I don't want to be dependent on this activity. I want to check with the packageManager and then call it via string – Elad Benda Aug 13 '19 at 15:04
  • I think the compiler needs to know which activity class you are refering to at compile time i.e. you need a dependency on InternalDummyActivity, or try passing a non final String parameter to new ComponentName() – matdev Aug 13 '19 at 15:09
  • but then what's the point in this "string","string" signature? – Elad Benda Aug 13 '19 at 15:12
  • 1
    try using new ComponentName(context, "com.my.InternalDummyActivity"); – matdev Aug 13 '19 at 15:24
  • there is no such a signature. do you know of some? or just guessing? – Elad Benda Aug 14 '19 at 09:34
  • There is, look at the second constructor on the doc: https://developer.android.com/reference/android/content/ComponentName.html – matdev Aug 14 '19 at 10:02
0

This question is possible duplicate of the thread gives below How to call activity from a library module in android studio

Check if this is what you are looking for.

Ashok Kumar
  • 1,226
  • 1
  • 10
  • 14