简体   繁体   English

启动意图找不到活动

[英]Launching Intent cannot find Activity

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. 单击某人应编辑其详细信息,但是单击某人将引发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: AndroidManifest.xml的相关部分:

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

What's going on? 这是怎么回事?

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: 通常,如果您要在自己的应用程序内调用Activity,则要使用的是显式方法,因为它要容易得多:

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). 每个隐式意图过滤器都需要类别android.intent.category.DEFAULT (少数例外)。 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 . 建议阅读: 意图过滤器

When you instantiate your Adapter, pass the context from the calling activity. 实例化适配器时,请传递来自调用活动的上下文。 Then in your adapter use context.startActivity(...); 然后在您的适配器中使用context.startActivity(...);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM