0

so here's what i need : first page -> linked to second page (with several image button) -> linked to different third page.

now i have tried the "first page -> linked to second page" stage.

activity_main.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">
<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:textSize="20sp"
    android:text="This is first activity" />
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="14dp"
    android:text="Move to second activity" />
</RelativeLayout>

MainActivity.java :

package com.example.acer.myapplication;

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

public class MainActivity extends Activity {
  Button buttoon;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final Intent move= new Intent(this, ActivityTwo.class);
    buttoon=(Button) findViewById(R.id.button1);
    buttoon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(move);
        }
    });

  }
}

ActivityTwo.java :

package com.example.acer.myapplication;

import android.os.Bundle;
import android.app.Activity;
public class ActivityTwo extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_two);
    }
}

it is actually working when the second page DID NOT contained any image button.

activity_two.xml (WORKING) :

<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">
<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="92dp"
    android:text="Second activity"
    android:textSize="20sp" />
</RelativeLayout>

button without any image is also WORKING :

<Button
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Second activity" />

but when you added image, it's just not working.

using button with background image (NOT WORKING):

<Button
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Second activity"
    android:background="@drawable/image"/>

using image button (NOT WORKING):

<ImageButton
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Second activity"
    android:src="@drawable/image"/>

and i really need for the second page to have image button. please enlighten me where am i wrong or is there another trick.

ps : when i say not working i mean it build smoothly but it just forced closed in the android phone when the intent is called. so no logcat entries.

2 Answers2

0

Your image is probably too large and you are getting an OOME (Out Of Memory Error)

Force close after first run

Decrease the size of your image. The "default" heap size is usually 24MB (https://code.google.com/p/android/issues/detail?id=14869) which is really easy to burn past.

You probably need to increase the heap size on the device for your app:

How to increase heap size of an android application?

EDIT:

I should add that you should make every effort to reduce image sizes before automatically increases the heap size. Otherwise, you will run out of heap later and then have a huge mess cleaning up all the image files that are too large.

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36
0

Resize your image, try 100dp x 100dp and put it in your drawable folder. Increasing heap size is not recommendable.

Stanojkovic
  • 1,612
  • 1
  • 17
  • 24