Reputation: 11
I'm making very simple an application contains 38 image, when I run the application I got this message:
Unfortunately, MyAppName has stopped.
when I click OK the application go back work, Then next few pages do the same thing.
My application run without need connect to the internet ,
Here is my LogCat:
Out of memory on a 12566540-byte allocation. FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Web.myappname/com.Web.myappname.A4}: android.view.InflateException: Binary XML file line #2: Error inflating class
I using the image in background.
This is XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android1:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/image_01" >
<Button
android1:id="@+id/button1"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignParentLeft="true"
android1:layout_alignParentTop="true"
android1:text="Main"
android1:textStyle="bold"
tools:ignore="HardcodedText" />
<Button
android1:id="@+id/button2a1"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_alignParentRight="true"
android1:layout_alignParentTop="true"
android1:text="Next"
android1:textStyle="bold"
tools:ignore="HardcodedText" />
</RelativeLayout>
and java file:
package com.web.myappname;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class A1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.a1);
Button main = (Button) findViewById(R.id.button1);
main.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(A1.this, MainActivity.class));
}
});
Button forward = (Button) findViewById(R.id.button2a1);
forward.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(A1.this, A2.class));
}
});
}
}
Any kind of help or suggestion is much appreciated. Thanks !
Upvotes: 0
Views: 690
Reputation: 4381
This might be useful: android:largeHeap="true"
It tells android it would like a larger heap allocation. However Android doesn't have to respect it. This may "fix" your problem however I also believe it is a poor solution.
Upvotes: 0
Reputation: 8383
Bitmap image requires a lot of memory and your application got out of memory while loading images. You have to load large bitmap effectively. Please see how to load large bitmap in Android.
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Android Universal Image Loader is also good alternative.
Upvotes: 0
Reputation: 15798
Without code it's very hard to suggest anything.
Your application is crashing because you are loading heavy images without recycling memory. It's always tricks with images. Maybe if you try it on a phone with low memory your application will crash even sooner.
Solution: The best thing to do is use an external good library for loading images. It will take care everything for you and your application will not crash when you don't free memory.
Most commonly used library is https://github.com/nostra13/Android-Universal-Image-Loader
Upvotes: 1