gpt4 book ai didi

java - Android Activity list 错误

转载 作者:行者123 更新时间:2023-11-29 21:08:54 26 4
gpt4 key购买 nike

我正在尝试运行一个指向 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com