0

I am getting an ActivityNotFoundException for an activity which exists and is included in my applications AndroidManifest.xml.

Here is my scenario:

My Application project package is: com.myapplynx.mytexteditor.android.

My library project package is com.myapplynx.mytexteditor.common

My library project is properly included in my application project as I can use other classes in the library project from within my application project.

The activity MyTedAdvancedPreference is found in my library project under com.myapplynx.mytexteditor.common.prefs package.

In my application project, I have an xml, res/xml/prefs.xml, where I have defined preferences, including a preference screen to call MyTedAdvancedPreference as shown below:

    <PreferenceScreen android:title="@string/config_cat_advanced" >
        <intent android:action="android.intent.action.VIEW"
            android:targetPackage="com.myapplynx.mytexteditor.android"
            android:targetClass="com.myapplynx.mytexteditor.common.prefs.MyTedAdvancedPreferences"/> 

Note that MyTedAdvancedPreferences is included in my application project AndroidManifest.xml as :

  <application
   .....
   <activity android:name="com.myapplynx.mytexteditor.common.prefs.MyTedAdvancedPreference"
       android:label="@string/title_settings"
         android:theme="@style/MyApplynxTheme" >       
    </activity>
   ....
   </application>

My application compiles and runs OK. So when I access my settings page and try to access MyTedAdvancedPreference, I get an ActivityNotFoundException:

10-25 14:15:52.734: E/AndroidRuntime(19049): FATAL EXCEPTION: main
10-25 14:15:52.734: E/AndroidRuntime(19049): android.content.ActivityNotFoundException:   Unable to find explicit activity class {com.myapplynx.mytexteditor.android/com.myapplynx.mytexteditor.common.prefs.MyTedAdvancedPreferences}; have you declared this activity in your AndroidManifest.xml?

The activity is defined in my applications(com.myapplynx.mytexteditor.android) AndroidManifest.xml. What am I doing wrong? Thanks.

nmvictor
  • 1,109
  • 1
  • 15
  • 30

3 Answers3

1

It looks similar to another question ActivityNotFoundException when different package's targetClass in PreferenceScreen

Here is the answer that describes a workaround, suggesting that this is a bug in the framework:

What he suggests is inheriting from the "broken" Activity, placing the inherited code inside your main app project. Then reference that as per normal in your main manifest.

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
0

In your manifest change this:

   <activity android:name="com.myapplynx.mytexteditor.common.prefs.MyTedAdvancedPreference"
   android:label="@string/title_settings"
     android:theme="@style/MyApplynxTheme" >       
</activity>

to this:

   <activity
            android:name="MyTedAdvancedPreference"
            android:label="@string/title_settings"
            android:theme="@style/MyApplynxTheme" >
            <intent-filter>
                <action android:name="example.action.ACTION_PREF_ACTIVITY" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

And your pref.screen should look like this:

    <PreferenceScreen android:title="@string/config_cat_advanced" >
        <intent android:action="example.action.ACTION_PREF_ACTIVITY" >
        </intent>
    </PreferenceScreen>
Dyna
  • 2,304
  • 1
  • 14
  • 25
  • @nmvictor I updated the answer, the `action android:name` should be equal to the action you are defining in your pref.screen. I you need any help with this let me know. – Dyna Oct 25 '13 at 13:24
0

Try adding the Intent-Filter and give the

Action(com.myapplynx.mytexteditor.common.prefs).

  <application
       .....
       <activity android:name="com.myapplynx.mytexteditor.common.prefs.MyTedAdvancedPreference"
           android:label="@string/title_settings"
             android:theme="@style/MyApplynxTheme" >
        <intent-filter>
                <action android:name="com.myapplynx.mytexteditor.common.prefs" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>       
        </activity>
       ....
       </application>

And try to call Activity like

Intent intent=new Intent("com.myapplynx.mytexteditor.common.prefs");//action
intent.startActivity(intent);

Hope it should work.

Amit Gupta
  • 8,914
  • 1
  • 25
  • 33
  • not exactly what I am looking to achieve since I need to call the activity from the prefs.xml. Unless you gave an example with that. Thanks though. – nmvictor Oct 25 '13 at 12:04