gpt4 book ai didi

android - 无法找到明确的 Activity 类,即使我在 list 中声明了 Intent

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

我在 list 中声明了一项 Activity :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my">
<uses-sdk android:minSdkVersion="14"/>
<application>
<activity
android:name="com.my.InternalDummyActivity"
android:exported="false">
</activity>
</application>
</manifest>

我也尝试过不使用 exported=false

应用程序包含一个带有另一个 Activity 的内部库。

我尝试从其他 Activity (其他 namespace )调用显式 Intent 但我总是得到一个异常(exception):

Intent intent1 = new Intent(activity.getApplicationContext(), InternalDummyActivity.class);
activity.startActivity(intent1);


ComponentName componentName2 =
new ComponentName(
"com.my","com.my.InternalDummyActivity");
Intent intent2 = new Intent().setComponent(componentName2); //dones work
activity.startActivity(intent2);


Process: com.comp.outter, PID: 9267
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.my/com.my.InternalDummyActivity}; have you declared this activity in your AndroidManifest.xml?

我该如何解决这个问题?

最佳答案

尝试使用 ComponentName 的 contructors 之一使用上下文的,例如

ComponentName cn = new ComponentName(context,
"com.my.InternalDummyActivity");

出于某种原因,只有当您动态知道类时,您才能使用带两个字符串的构造函数。

此外,按如下方式更新您的 list :

<activity
android:name=".InternalDummyActivity">
</activity>

和应用程序包名称应仅使用小写,如 Oracle Docs 中的 Java 命名约定所述。

Package names are written in all lower case to avoid conflict with the names of classes or interfaces

关于android - 无法找到明确的 Activity 类,即使我在 list 中声明了 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57478796/

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