user1905568
user1905568

Reputation: 35

Android activity manifest error

I am trying to run an activity which points to Result.java here is my file 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);
            }

        }
    });

}



}

and here is the android manifest

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

The problem is that the code is not switching to the activity Results.java the same Intent has worked for me in the past but I cannot for the life of me understand why is it not switching to the Results activity

Your help will be greatly appreciated

Upvotes: 1

Views: 857

Answers (4)

Hai
Hai

Reputation: 690

You have multiple issues with your manifest file:

1) First remove this from your Result activity

    <intent-filter>
        <action android:name="android.intent.action.lAUNCHER" />

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

If this is an activity that you launch internally from your code, you don't need this.

2) Intent actions are defined here: https://developer.android.com/reference/android/content/Intent.html You don't need to define your own ones, like android.intent.action.Cube

Upvotes: 0

karan
karan

Reputation: 93

change this

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

to

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

and how can every activity be LAUNCHER keep one activity LAUNCHER which is your first activity and make rest DEFAULT

Upvotes: 0

georgeok
georgeok

Reputation: 5696

Remove the following code from your manifest:

 <intent-filter>
            <action android:name="android.intent.action.lAUNCHER" />

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

Upvotes: 0

Raghunandan
Raghunandan

Reputation: 133560

Change this

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

to

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

The same for all others except MainActivity which should probably be the 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.

You don't need intent-filter. You can use Explicit Intents

Upvotes: 2

Related Questions