10

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?

Community
  • 1
  • 1
an00b
  • 11,338
  • 13
  • 64
  • 101
  • 1
    Whats com.example.baseapp.paypal?? Are you using some paypal library? – Ravi Vyas Jun 14 '11 at 19:05
  • @Ravi Vyas Yes, I am. This is the main reason I broke the monolithic application project to a 2-part project: library that is common to all Android markets and a tiny application project (with activity class derived from library activity class) that is customized to each Android market or appstore. Did you notice something? – an00b Jun 14 '11 at 19:09
  • I do not believe you can create an intent to call a class like that that is in a different package. – Maximus Jun 14 '11 at 19:10
  • apart from your awesome rep score of 404 I cant seem to find anything with the information given :-( – Ravi Vyas Jun 14 '11 at 19:12
  • @Maximus Why? I managed so far to solve all problems that stemmed from breaking the monolithic application project to a 2-part project. Sometimes it involved ugly workarounds like [duplicating all assets](http://stackoverflow.com/questions/6346889/how-to-reference-an-asset-in-a-library-project/6347111#6347111) but it works at least. If you could explain why, I may be able to come up with a workaround. :) – an00b Jun 14 '11 at 19:32

5 Answers5

14

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.

an00b
  • 11,338
  • 13
  • 64
  • 101
  • here it is written: http://developer.android.com/tools/projects/projects-eclipse.html – user1324936 Nov 24 '13 at 12:47
  • "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." – Sandy Oct 14 '14 at 15:44
1

Maybe this will work?

Intent mIntent = new Intent();
mIntent.setClassName(mActivity, "com.example.baseapp.MyEditPreferences");
mActivity.startActivity(mIntent);
Maximus
  • 8,351
  • 3
  • 29
  • 37
  • 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: http://stackoverflow.com/questions/5363548/activitynotfound-exception-thrown-for-a-preferenceactivity-listed-in-the-manifest/5363603#5363603 The FQN approach worked him, but didn't solve the problem for me. Any other ideas? – an00b Jun 14 '11 at 19:56
0

If you use classes which names are included in an android package (Settings, Preferences, Activity, ...), you will need to put this:

Intent i = new Intent(this, <name_of_your_package>.classname.class);

If you don't put "name_of_your_package", the compiler will think that you are refering to the class in android package (android.*).

trumpetero
  • 153
  • 1
  • 1
  • 12
-1

I know this is a very old thread, but I've just had the same problem. In my case all I had to do was to delete a spurious

import java.util.prefs.Preferences;
Kevin Gilbert
  • 671
  • 10
  • 18
-2

Just check your manifest for errors that your IDE not pointed.

Smaran
  • 1
  • 1