在android中未调用onCreate方法

在android中未调用onCreate方法,android,android-intent,android-manifest,Android,Android Intent,Android Manifest,我已经创建了2个活动。当我通过intent从第一个活动调用第二个活动时,第二个活动的onCreate方法就不会被调用。尽管第一个活动的onCreate方法是正常调用的。 下面是第一个活动的代码。 第二个活动的代码。 Manifest.xml 您有 <activity android:name=".ShowValueActivity" android:label="@string/title_activity_show_value" >

我已经创建了2个活动。当我通过intent从第一个活动调用第二个活动时,第二个活动的onCreate方法就不会被调用。尽管第一个活动的onCreate方法是正常调用的。 下面是第一个活动的代码。

第二个活动的代码。

Manifest.xml


您有

   <activity
        android:name=".ShowValueActivity"
        android:label="@string/title_activity_show_value" >
    </activity>

尽管如此,为什么应用程序没有崩溃,并说
NoActivityFoundException

请查看清单 改变



你的清单应该是这样的

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.webesperto.webespertofirstapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.webesperto.webespertofirstapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
             android:name=".ShowValue"
        android:label="@string/title_activity_show_value" >
        </activity>
    </application>

</manifest>

更改类文件中的第二个活动名称,如下所示:

package com.webesperto.webespertofirstapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class ShowValueActivity extends Activity {

TextView tv_showValue1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.show_value);
    tv_showValue1 = (TextView) findViewById(R.id.tv_showValue);
    Intent gotIntent = (Intent) this.getIntent();
    Bundle gotBundle = gotIntent.getExtras();
    tv_showValue1.setText(gotBundle.getString("key"));
}

}

它将起作用:)

在AndroidManinfest.xml和java文件中定义的活动名称之间存在差异。在清单中,它是ShowValueActivity,基本上是ShowValue.java
   <activity
        android:name=".ShowValueActivity"
        android:label="@string/title_activity_show_value" >
    </activity>
<activity
        android:name=".ShowValue"
        android:label="@string/title_activity_show_value" >
    </activity>
public class ShowValue extends Activity {
<activity
        android:name=".ShowValueActivity"
        android:label="@string/title_activity_show_value" >
    </activity>
<activity
        android:name=".ShowValue"
        android:label="@string/title_activity_show_value" >
    </activity>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.webesperto.webespertofirstapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.webesperto.webespertofirstapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
             android:name=".ShowValue"
        android:label="@string/title_activity_show_value" >
        </activity>
    </application>

</manifest>
package com.webesperto.webespertofirstapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class ShowValueActivity extends Activity {

TextView tv_showValue1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.show_value);
    tv_showValue1 = (TextView) findViewById(R.id.tv_showValue);
    Intent gotIntent = (Intent) this.getIntent();
    Bundle gotBundle = gotIntent.getExtras();
    tv_showValue1.setText(gotBundle.getString("key"));
}

}