gpt4 book ai didi

安卓 ActivityNotFoundException

转载 作者:行者123 更新时间:2023-11-29 16:25:01 25 4
gpt4 key购买 nike

我正在尝试创建一个非常简单的自定义 Intent 示例。我已经搜索过这个错误,但没有一个论坛有适合我的答案。这是我的文件:

public class DemoImplicit extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

public void whenButtonIsClicked(View view) {
Intent intent = new Intent("com.example.action.NEW_ACTION"); //<<<<<<<
intent.addCategory("android.intent.category.DEFAULT"); //<<<<<<<
// Intent intent = new Intent("android.intent.action.VIEW");
// intent.addCategory("com.example.MY_CATEGORY");
startActivity(intent); //<<<<<<<
}
}

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demos" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".SatisfyIntent" android:label="@string/app_name">

<intent-filter>
<!-- action android:name="android.intent.action.VIEW" / -->
<!-- category android:name="com.example.MY_CATEGORY" / -->
<action android:name="com.example.action.NEW_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="9" />

</manifest>

这两个单独的文件位于两个不同的 Eclipse 项目中,但我确保在将包含 startActivity 调用的文件加载到模拟器之前将包含 intent-filter 的项目加载到模拟器。无论如何,我总是得到一个 ActivityNotFoundException。我做错了什么?

附言这是包含 DemoImplicit.java 的项目的 AndroidManifest.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demos"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".DemoImplicit"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="9" />

</manifest>

最佳答案

首先你应该确保你的AndroidManifest.xml文件必须定义了 DemoImplicit这方面的 Activity 。

像这样:<activity android:name=".DemoImplicit"/>

还在您的代码中指定了 SatisfyIntent作为启动器 Activity

<activity android:name=".SatisfyIntent" android:label="@string/app_name">

但是在这里,您的 Java 代码中似乎没有类似的东西。

所以底线是:Activity你想运行的必须在你的 AndroidManifest.xml 中定义文件。

关于安卓 ActivityNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4911694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com