[英]Android activity manifest error
我正在嘗試運行指向Result.java的活動,這是我的文件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);
}
}
});
}
}
這是Android清單
<?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,而過去同樣的Intent對我有用,但是我一生都無法理解為什么不切換到Results活動
對你的幫助表示感謝
改變這個
<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
之外的所有其他活動都應相同,這可能應該是Launcher活動
http://developer.android.com/guide/components/intents-filters.html
明確的意圖指定組件以名稱(全限定類名)開頭。 通常,您將使用明確的意圖在自己的應用程序中啟動組件,因為您知道要啟動的活動或服務的類名。 例如,響應用戶操作而啟動新活動,或啟動服務以在后台下載文件。
您不需要意圖過濾器。 您可以使用明確意圖
從清單中刪除以下代碼:
<intent-filter>
<action android:name="android.intent.action.lAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
改變這個
<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" >
<intent-filter>
<action android:name="android.intent.action.Result" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
以及如何開展每項活動保持一項活動為您的第一項活動,並確保休息默認
清單文件存在多個問題:
1)首先從您的Result活動中刪除它
<intent-filter>
<action android:name="android.intent.action.lAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
如果這是您從代碼內部啟動的活動,則不需要此活動。
2)意圖動作在這里定義: https : //developer.android.com/reference/android/content/Intent.html您不需要定義自己的動作,例如android.intent.action.Cube
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.