views:

74

answers:

2

My program has a list of tabs that each contain a list of people. Clicking a person should edit their details, but instead, clicking a person throws an ActivityNotFoundException. My code that starts the edit activity:

Intent intent = new Intent("my.package.EDIT");                // Person is both
intent.putExtra("my.package.PERSON", (Parcelable) myPerson);  // Parcelable and
GroupArrayAdapter.this.getContext().startActivity(intent);    // Serializable

Relevant part of AndroidManifest.xml:

<activity android:name="EditActivity">
  <intent-filter>
    <action android:name="my.package.EDIT" />
  </intent-filter>
</activity>

What's going on?

+2  A: 

There's two ways to start an Activity, either explicitly or implicitly. Explicitly means that you use the class name directly; usually if you're calling an Activity that is within your own application, what you mean to use is the explicit method because it's far easier:

Intent intent = new Intent(context, EditActivity.class);
context.startActivity(intent);

However, if you really do mean to use implicit filtering, then your intent filter is missing something. Every implicit intent filter requires the category android.intent.category.DEFAULT (with few exceptions). Try this and see if it works:

<activity android:name="EditActivity">
  <intent-filter>
    <category android:name="android.intent.category.DEFAULT" />
    <action android:name="my.package.EDIT" />
  </intent-filter>
</activity>

Suggested reading: intent filters.

Daniel Lew
A: 

When you instantiate your Adapter, pass the context from the calling activity. Then in your adapter use context.startActivity(...);

Ricardo Villamil