0

I've been searching about this problem a lot before posting this question but still couldnt get any help,kindly help me in solving this problem in which when I press the button a black page appears and then the app closes saying its not responding,im a newbie over here and any kind of help will be appreciated.

activity_main

 <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: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="com.example.firstapp.MainActivity" >

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageView1"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="26dp"
    android:ems="10"
    android:inputType="numberPassword" />

<EditText
    android:id="@+id/editText5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/editText1"
    android:layout_alignLeft="@+id/editText1"
    android:ems="10"
    android:inputType="textMultiLine"
    android:text="Enter your Password"
    tools:ignore="HardcodedText" />

<EditText
    android:id="@+id/editText3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/editText5"
    android:layout_alignLeft="@+id/editText5"
    android:layout_marginBottom="20dp"
    android:ems="10"
    android:inputType="textEmailAddress" >

    <requestFocus android:layout_width="wrap_content" />

</EditText>

<EditText
    android:id="@+id/editText4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/editText3"
    android:layout_alignLeft="@+id/editText3"
    android:ems="10"
    android:inputType="textMultiLine"
    android:text="Enter your E-mail id"
    tools:ignore="HardcodedText" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/editText4"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="36dp"
    android:src="@drawable/robo" 
    android:contentDescription="@null"/>

<EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="38dp"
    android:ems="10"
    android:inputType="textMultiLine"
    android:text="Welcome To Foodparkk"
    tools:ignore="HardcodedText" />

<Button
    android:id="@+id/button_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="Login" />

 </RelativeLayout>

MainActivity.java

 package com.example.firstapp;

 import com.example.firstapp.R;
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.Menu;
 import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final Button button = (Button) findViewById(R.id.button_id);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(),Second.class);
            startActivity(i);
        }
    });
}

@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;
}

@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();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
 }

Second.java

   package com.example.firstapp;

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

  public class Second extends ActionBarActivity {

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

    @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;
    }

    @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();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
 }

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: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="com.example.firstapp.Second" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />
  </RelativeLayout>

manifest code

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

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

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
       </activity>
      <activity
        android:name=".Second"
        android:label="@string/title_activity_second" >
      </activity>
     </application>

     </manifest>
Shashwat
  • 31
  • 6

2 Answers2

1
 public class MainActivity extends ActionBarActivity { //mainactivity class

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 Button button = (Button) findViewById(R.id.button_id);
 button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Intent i = new Intent(MainActivity.this,Second.class);
        startActivity(i);
      }
   });
 }

then your manifest

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Base.AppCompat.Light.DarkActionBar" > // i changed this
<activity
    android:name=".MainActivity"
    android:label="@string/title_activity_main" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
   </activity>
  <activity
    android:name=".Second"
    android:label="@string/title_activity_second" >
  </activity>
 </application>

if you extend actionbarActivity its xml should use its style's, i dont wona story this, so i will repharse it in my edit. simply to say your second activity doesn't have style set so it uses the device default theme for the activity set in your application so copy paste the respective codes in mine to yours

Elltz
  • 10,730
  • 4
  • 31
  • 59
-2

It's called ANR short for Android Not Responding. Your app is doing so much processing in the main thread. Consider using a background Thread or AsyncTask along with ProgressDialog so that the main thread is not affected by the processing part.

Read more about it in the documentation. Also refer to this post for more info.

Community
  • 1
  • 1
Abdallah Alaraby
  • 2,222
  • 2
  • 18
  • 30