Activities and the manifest in Android



我知道有很多关于这个问题,但我只是不能弄清楚为什么我的程序一直加载错误的活动,即使我已经使正确的一个默认的manifest。下面是一些代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="swin.examples"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name="swin.examples.TemperatureConvertor"
                  android:label="@string/app_name">
        </activity>        
        <activity android:name="swin.examples.FeetToCmConvertor"
                  android:label="@string/app_name">
        </activity>
        <activity android:name="swin.examples.Main" 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>
</manifest> 

如果它不在清单中,我认为问题就在这里:

package swin.examples;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Main extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initializeUI();
    }
private void initializeUI()
{
    Button btnCm = (Button)findViewById(R.id.btnFeet);
    btnCm.setOnClickListener(btnFeetListener);
    Button convertButton = (Button)findViewById(R.id.btnTemp);
    convertButton.setOnClickListener(btnTempListener);
}
/** Handle convert button click */ 
private OnClickListener btnTempListener = new OnClickListener() 
{
    public void onClick(View v) 
    {
            convertButtonClicked();
    }
};
private OnClickListener btnFeetListener = new OnClickListener() 
{
    public void onClick(View v) 
    {
            btnCmClicked();
    }
};
private void btnCmClicked()
{
    // set the sender and the receiver of the intent
    Intent intent = new Intent();
    intent.setClass(getApplicationContext(), swin.examples.FeetToCmConvertor.class);
    startActivity(intent); // transmit your intent
}
private void convertButtonClicked()
{
    // set the sender and the receiver of the intent
    Intent intent = new Intent();
    intent.setClass(getApplicationContext(), swin.examples.TemperatureConvertor.class);
    startActivity(intent); // transmit your intent  
}
}
我想不出来,希望你能帮助我!提前谢谢你!

编辑:代码更新,但仍然不能工作。如果有帮助,下面是日志消息:

[2013-04-20 22:44:20 - CombinedConvertor] Success!
[2013-04-20 22:44:21 - CombinedConvertor] Starting activity swin.examples.TemperatureConvertor on device emulator-5554
[2013-04-20 22:44:23 - CombinedConvertor] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=swin.examples/.TemperatureConvertor }

合适的IntentFilter为主Activity

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

最奇怪的bug。对其他人都有用,但对我没用。重新制作温度转换器活动,它现在工作。谢谢大家的帮助!

最新更新