Android 在安卓系统中,意图并非总是以相同的方式工作

Android 在安卓系统中,意图并非总是以相同的方式工作,android,android-intent,Android,Android Intent,有2-3种方法可以使用意图启动新活动。 大多数情况下,我使用的是 Intent openStartingPoint = new Intent("com.Example.Jeeten.Connection"); startActivity(openStartingPoint); 但有时,它不起作用,它显示未找到错误活动,在这种情况下,如果我使用 Intent openStartingPoint = new Intent(Connection.this, Hello.class); startAc

有2-3种方法可以使用意图启动新活动。 大多数情况下,我使用的是

Intent openStartingPoint = new Intent("com.Example.Jeeten.Connection");
startActivity(openStartingPoint);
但有时,它不起作用,它显示未找到错误活动,在这种情况下,如果我使用

Intent openStartingPoint = new Intent(Connection.this, Hello.class);
startActivity(openStartingPoint);

那么它工作得很好。这会有什么问题?

当您进行活动时,必须将其注册到AndroidManifest.xml文件中

<activity
        android:name=".Connection"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.Example.Jeeten.CONNECTION" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

你能用一个例子解释一下当第一种方法不起作用时,你应该仔细阅读Intent类@ρ砦σρѕρєK的不同构造函数,它显示错误“未找到活动”。@JeetenParmar:只有当您忘记在案例中为活动定义相同的操作com.Example.Jeeten.Connection(使用AndroidManifestIntent中的意图过滤器)时,第一种方法才起作用。对于启动活动的各种方式,intent没有提供构造函数,因此请理解不同的构造函数的意图。。。
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />