tags:

views:

47

answers:

3

I am programming an app that eventually will have several Activities. Right now, however, I got stuck trying to start the second activity from the first one. For some odd reason I am always only getting an ActivityNotFoundException.

The code that tries to start the second activity reads:

    ...
    Intent intent = new Intent(Intent.ACTION_INSERT);
     /* intent.addCategory("foo"); */
    Log.v(TAG, "starting activity: " + intent);             
    startActivity(intent);
    ...

The Intent.ACTION_INSERT string constant is "android.intent.action.INSERT".

The corresponding fragment in the AndroidManifest.xml reads:

    ...
    <activity 
        android:label="@string/item_details" 
        android:name="ItemDetails"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.INSERT" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="foo" />
        </intent-filter>
    </activity>
    ...

The Activity class "ItemDetails" exists and is in the same package as the "calling" Activity. The Intent names match and according to the Android docs the "android.intent.category.DEFAULT" category should apply to all Intents that have no category set. Still, that Activity is not found. Why?

I also tried to specify a unique category "foo" as shown in the commented line in the code snippet and also added that to the manifest file, but same result.... :-(

What am I missing? Any hints?

A: 

You need to specify the activity you want to start in the Intent.

intent.setClass(this, YourActivityClass.class);

Right now it looks like you're firing an Intent that doesn't have a target.

iandisme
No, even though your example will work for starting activity, the code from question should work as well. So that looks like just a workaround.
Konstantin Burov
+1  A: 

The android:name for your Activity should be the full path to the Activity, including the packages. Is that what you have?

Also, this may not be right for you, but for Activities that are only meant to be called from within your application you can just use an explicit intent:

Intent intent = new Intent(this, ItemDetails.class);
Mayra
A: 

Aaah! Finally I got the reason! I missed to add the package-prefix to the Activity's classname. I had thought that the package="..." attribute of the manifest tag would take care of that...

Sorry for the bandwidth then...

Michael

ADDED LATER: Thanks folks! You pointed it out. I saw your appends only later, though...

mmo
In case you activity class is placed at the same package as specified by application you may provide only the name of the class.
Konstantin Burov