java - Android Activity list 错误

标签 java android android-activity android-manifest

我正在尝试运行一个指向 Result.java 的 Activity ,这里是我的文件 Tables.java

package com.example.squarecube;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Tables extends Activity{
TextView t1,t2;
EditText e1;
Button b1;
int a,b,ans;
int score,trials;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab);
    trials = 0;
    score = 0;
    t1 = (TextView) findViewById(R.id.text);
    t2 = (TextView) findViewById(R.id.text2);
    e1 = (EditText) findViewById(R.id.ans);
    b1 = (Button) findViewById(R.id.but);
    a= (int)Math.floor(Math.random() * 7) +13;
    b= (int)Math.floor(Math.random() * 9) + 1;
    t1.setText("What is " + a + "*" + b);
    b1.setText("Answer");
    t2.setText("Score : "+ score + "\nTrials : " + trials);
    b1.setOnClickListener(new View.OnClickListener()
    {

        @Override
        public void onClick(View arg0) {
            String no = e1.getText().toString();
            ans = Integer.parseInt(no);
            if (a*b == ans)
            {
                t1.setText("Correct");
                trials++;
                score++;
            }
            else
            {
                t1.setText("Wrong");
                trials++;
            }
            a= (int)Math.floor(Math.random() * 7) +13;
            b= (int)Math.floor(Math.random() * 9) + 1;
            t1.setText("What is " + a + "*" + b);
            t2.setText("Score : "+ score + "\nTrials : " + trials);
            if (trials >= 10)
            {
                Intent abc = new Intent(Tables.this,Result.class);
                Bundle myBun = new Bundle();
                myBun.putInt("score", score);
                abc.putExtras(myBun);
                startActivity(abc);
            }

        }
    });

}



}

这是安卓 list

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

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

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
     <activity
        android:name="com.example.squarecube.Cube"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.Cube" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.squarecube.Tables"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.Tables" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.squarecube.Menu"
        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="com.example.squarecube.Result"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.lAUNCHER" />

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

</manifest>

问题是代码没有切换到 Results.java Activity ,同样的 Intent 在过去对我有用,但我无法理解为什么它没有切换到 Results Activity

非常感谢您的帮助

最佳答案

改变这个

<activity
    android:name="com.example.squarecube.Result"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.lAUNCHER" />

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

 <activity
    android:name="com.example.squarecube.Result"
    android:label="@string/app_name" >    
</activity>

MainActivity 外其他所有 Activity 都相同,它可能应该是 Launcher Activity

http://developer.android.com/guide/components/intents-filters.html

Explicit intents specify the component to start by name (the fully-qualified class name). You'll typically use an explicit intent to start a component in your own app, because you know the class name of the activity or service you want to start. For example, start a new activity in response to a user action or start a service to download a file in the background.

你不需要 Intent 过滤器。您可以使用显式 Intent

关于java - Android Activity list 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23596477/

相关文章:

java - Log4J 中的阈值是什么意思?

java - 是否可以在请求作用域 bean 中获取请求对象?

java - Android Fragments是View还是ViewGroup

android - 无法向 ListView 添加值

java - 自定义 ListView 人口项目未显示

android - Canvas.drawText() 是如何真正绘制文本的?

android - 如果 Asynctask 正在运行,即使在 finish() 方法之后 Activity 是否仍然存在?

android - 从 onActivityResult 获取数据到 fragment 的最佳做法是什么?

android - 如何在 Activity 完成时取消 AsyncTask?

java - Gradle在项目外部编译依赖项