android - Android 中的 Activity 和 list

标签 android android-activity manifest default

我知道对此有很多问题,但我就是无法弄清楚为什么我的程序不断加载错误的 Activity ,即使我已将正确的 Activity 设置为 list 中的默认 Activity 。这是给大家的一些代码:

<?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> 

如果它不在 list 中,我认为问题将出在此处:

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 }

最佳答案

主要Activity的正确IntentFilter

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

关于android - Android 中的 Activity 和 list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16120344/

相关文章:

android - URL中不同字段的含义

Android - 当应用程序在后台时启动一个新 Activity

java - 更改 Android Studio 中的默认 LAUNCHER Activity

HTML5 应用缓存 : How to exclude the htm-file from cache where the manifest is defined

java - Android - 单击发送到其他 Activity 的图像时应用程序崩溃

java - "Could not find the main class: bla.bla.yada",尽管在 MANIFEST.MF 中指定正确

android - 如何降级 Android SDK 中的 Google Play 服务库?

java - 通过 edittext SELECT 获取选择查询

android - 错误类型3错误: Activity class {com. rnnpro1/com.rnnpro1.MainActivity}不存在

android - 使用自定义操作启动 Activity