Activity won't start even after I add it to AndroidManifest

I am new to Android. I've read similar posts but I can't seem to solve my problem. I have added all my activities to androidManifest file but cannot navigate from Second Activity to ThirdActivity with Intent.

Here is MainActivity.java

package com.mobi.crazycalc;

  import android.os.Bundle;
  import android.os.Handler;
  import android.app.Activity;
  import android.content.Intent;
  import android.view.Menu;

  public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            Intent in= new Intent(MainActivity.this,SecondActivity.class);
            MainActivity.this.startActivity(in);
            MainActivity.this.finish();
        }
    }, 1000);
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
 }

 }

      

here SecondActivity.java

package com.mobi.crazycalc;

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

public class SecondActivity extends Activity {
EditText name1;
EditText name2;
Button goButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
    name1= (EditText) findViewById(R.id.name1);
    name2=(EditText) findViewById(R.id.name2);
    goButton= (Button) findViewById(R.id.gobutton);
    final String hisName=name1.getText().toString().trim();
    final String herName=name2.getText().toString().trim();
    goButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            Love lv=new Love();
            int result=lv.getLovePer(hisName, herName);
            Intent in=new Intent(SecondActivity.this,ThirdActivity.class);
            in.putExtra("Result", result);
            startActivity(in);

        }
    });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.second, menu);
    return true;
     }

    }

      

This is where ThirdActivity.java is located

package com.mobi.crazycalc;

import java.util.Random;

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

public class ThirdActivity extends Activity {
 TextView meter;
 Button goBackButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_third);
    meter = (TextView) findViewById(R.id.meter);
    goBackButton = (Button) findViewById(R.id.gobackbutton);
    goBackButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent in=new Intent(ThirdActivity.this,SecondActivity.class);
            startActivity(in);
        }
    });
    Random ran= new Random();
    for(int i=0;i<100;++i)
    {
        int ranNo=ran.nextInt(100);
        meter.setText(ran.toString());
    }
Bundle bund=getIntent().getExtras();
int res=bund.getInt("Result");

    meter.setText(res);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.third, menu);
    return true;
}

}

      

this is the manifest file -

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

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.mobi.crazycalc.MainActivity"
        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.mobi.crazycalc.SecondActivity"
        android:label="@string/title_activity_second" >
    </activity>
    <activity
        android:name="com.mobi.crazycalc.ThirdActivity"
        >
    </activity>
</application>

</manifest>

      

Activity-second.xml:

RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e52850"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SecondActivity" >

<EditText
    android:id="@+id/name1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="57dp"
    android:ems="10"
    android:hint="@string/name1Edittext"
    android:textColor="@color/almond" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/gobutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/name2"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="30dp"
    android:background="@android:color/transparent"
    android:text="@string/buttontext"
    android:textColor="@color/aeroBlue" />

<EditText
    android:id="@+id/name2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/name1"
    android:layout_below="@+id/name1"
    android:layout_marginTop="41dp"
    android:ems="10"
    android:hint="@string/name2Edittext"
    android:textColor="@color/almond" />

</RelativeLayout>

      

+3


source to share


1 answer


Try this

And you can check it here

In MainActiviy

package com.mobi.crazycalc;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                Intent in = new Intent(MainActivity.this, SecondActivity.class);
                MainActivity.this.startActivity(in);
                MainActivity.this.finish();
            }
        }, 1000);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

}

      

In SecondAcivity

package com.mobi.crazycalc;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class SecondActivity extends ActionBarActivity {

    EditText name1;
    EditText name2;
    Button goButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        name1 = (EditText) findViewById(R.id.name1);
        name2 = (EditText) findViewById(R.id.name2);
        goButton = (Button) findViewById(R.id.gobutton);
        final String hisName = name1.getText().toString().trim();
        final String herName = name2.getText().toString().trim();
        goButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent in = new Intent(SecondActivity.this, ThirdActivity.class);
                in.putExtra("Result", "value");
                startActivity(in);

            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_second, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

      



In the third act

package com.mobi.crazycalc;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Random;


public class ThirdActivity extends ActionBarActivity {

    TextView meter;
    Button goBackButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third);

        meter = (TextView) findViewById(R.id.meter);
        goBackButton = (Button) findViewById(R.id.gobackbutton);
        goBackButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent in = new Intent(ThirdActivity.this, SecondActivity.class);
                startActivity(in);
            }
        });
        Random ran = new Random();
        for (int i = 0; i < 100; ++i) {
            int ranNo = ran.nextInt(100);
            meter.setText(ran.toString());
        }
        Bundle bund = getIntent().getExtras();
        String res = bund.get("Result").toString();

        meter.setText(res);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_third, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

      

and in the manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mobi.crazycalc" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            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=".SecondActivity"
            android:label="@string/title_activity_second" >
        </activity>
        <activity
            android:name=".ThirdActivity"
            android:label="@string/title_activity_third" >
        </activity>
    </application>

</manifest>

      

Hope this helps you.

+1


source







All Articles