ActivityNotFoundException (YES, this activity is declared in AndroidManifest.xml)

13,596

Solution 1

I just solved the problem.

All I had to do was add the FQN to the Application project's AndroidManifest.xml:

<activity android:name="com.example.baseapp.MyEditPreferences"
          android:label="com.example.baseapp.MyActivityLib:string/app_name">
</activity>

In fact, I removed any reference to MyEditPreferences in the Library project's AndroidManifest.xml completely and it still works.

It also works with the original startActivity 1-line statement:

mActivity.startActivity(new Intent(mActivity, MyEditPreferences.class));

Conclusion: It's the application's AndroidManifest.xml that matters, not the library's.

Solution 2

Maybe this will work?

Intent mIntent = new Intent();
mIntent.setClassName(mActivity, "com.example.baseapp.MyEditPreferences");
mActivity.startActivity(mIntent);
Share:
13,596
an00b
Author by

an00b

Updated on June 15, 2022

Comments

  • an00b
    an00b about 2 years

    I found a few threads reporting a similar problem but none of them really offers something that I haven't tried already.

    An innocent such call:

    mActivity.startActivity(new Intent(mActivity, MyEditPreferences.class));
    

    with the following in AndroidManifest.xml:

     <application>
        <activity android:name="MyActivityLib" />
        <activity android:name="com.example.baseapp.MyEditPreferences" android:label="@string/app_name">
        </activity>
     </application>
    

    Triggers the following exception:

    06-14 14:06:50.297: ERROR/AndroidRuntime(9272): 
    android.content.ActivityNotFoundException: Unable to find explicit activity class
    {com.example.baseapp.paypal/com.example.baseapp.MyEditPreferences};
    have you declared this activity in your AndroidManifest.xml?
    

    The things is, this code used to work flawlessly before I changed it from a monolithic application project to a 2-part project that is comprised from a Library Project and an Application Project.

    The AndroidManifest.xml is the one in the library project.

    What do I need to do eliminate this ActivityNotFoundException?

  • an00b
    an00b about 13 years
    Thanks and +1 for the suggestion. I just tried it and it didn't help. I also found a thread describing an incredibly similar problem: stackoverflow.com/questions/5363548/… The FQN approach worked him, but didn't solve the problem for me. Any other ideas?
  • user1324936
    user1324936 over 10 years
  • Sandy
    Sandy over 9 years
    "In the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project."