0

when I'm opening a new screen with a button my app won't respond and show up ANR, because it costs my app to long for loading the page but I don't know how to fix my problem.

it works on a older android device but on my device the app has been stopped :'(

if you need more info just ask ;)

I have an HTC one X running on the newest version of android 4.1.1 I have an app you can listen and download music for free and I have a lot of views on 1 layout more than 80 views that's the problem.

i can give you the codes but all my codes are all working because on android 3.3.7 everything works fine on a Samsung galaxy mini. the problem is that i want give more time to my application for opening the new screen because I have read that after 5 seconds automatically the ANR pop up

logcat:

04-17 22:26:48.333: I/dalvikvm(20428):   at dalvik.system.NativeStart.main(Native Method)
04-17 22:26:48.333: E/dalvikvm(20428): Out of memory: Heap Size=65571KB, Allocated=62502KB, Limit=65536KB
04-17 22:26:48.333: E/dalvikvm(20428): Extra info: Footprint=63651KB, Allowed Footprint=65571KB, Trimmed=0KB
04-17 22:26:48.333: D/skia(20428): --- decoder->decode returned false
04-17 22:26:48.333: W/dalvikvm(20428): threadid=1: thread exiting with uncaught exception (group=0x41b4e2d0)
04-17 22:26:48.348: E/AndroidRuntime(20428): FATAL EXCEPTION: main
04-17 22:26:48.348: E/AndroidRuntime(20428): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.listentomusic/com.example.listentomusic.March}: android.view.InflateException: Binary XML file line #1209: Error inflating class <unknown>
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.app.ActivityThread.access$600(ActivityThread.java:151)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.os.Looper.loop(Looper.java:155)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.app.ActivityThread.main(ActivityThread.java:5485)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at java.lang.reflect.Method.invokeNative(Native Method)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at java.lang.reflect.Method.invoke(Method.java:511)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at dalvik.system.NativeStart.main(Native Method)
04-17 22:26:48.348: E/AndroidRuntime(20428): Caused by: android.view.InflateException: Binary XML file line #1209: Error inflating class <unknown>
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:365)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.app.Activity.setContentView(Activity.java:1912)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at com.example.listentomusic.March.onCreate(March.java:15)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.app.Activity.performCreate(Activity.java:5066)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
04-17 22:26:48.348: E/AndroidRuntime(20428):    ... 11 more
04-17 22:26:48.348: E/AndroidRuntime(20428): Caused by: java.lang.reflect.InvocationTargetException
04-17 22:26:48.348: E/AndroidRuntime(20428):    at java.lang.reflect.Constructor.constructNative(Native Method)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
04-17 22:26:48.348: E/AndroidRuntime(20428):    ... 26 more
04-17 22:26:48.348: E/AndroidRuntime(20428): Caused by: java.lang.OutOfMemoryError: (Heap Size=65571KB, Allocated=62502KB)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:626)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:473)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.content.res.Resources.loadDrawable(Resources.java:1959)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.widget.ImageView.<init>(ImageView.java:120)
04-17 22:26:48.348: E/AndroidRuntime(20428):    at android.widget.ImageView.<init>(ImageView.java:110)
04-17 22:26:48.348: E/AndroidRuntime(20428):    ... 29 more

xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/standaard_background" >

     <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/maart"
        android:textSize="30sp"
        android:textColor="#FFFFFF"
        android:background="#000000" />

     <android.support.v7.widget.Space
         android:id="@+id/space1"
         android:layout_width="fill_parent"
         android:layout_height="15dp" />

     <ListView
         android:id="@+id/scrollView1"
         android:layout_width="match_parent"
         android:layout_height="match_parent" >

         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:orientation="vertical" >
<!-- start -->             
<!-- song1 -->      
             <TextView
                 android:id="@+id/textView2"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:text="@string/s1" 
                 android:background="#FFFFFF"/>

             <ImageView
                 android:id="@+id/imageView1"
                 android:layout_width="match_parent"
                 android:layout_height="137dp"
                 android:contentDescription="@string/imageView1"
                 android:src="@drawable/a" />

             <LinearLayout 
                 android:orientation="horizontal"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content">

               <Button 
                 android:text="@string/play" 
                 android:id="@+id/btnsong1_1" 
                 android:layout_width="fill_parent" 
                 android:layout_height="wrap_content"
                 android:layout_weight="1">
               </Button>

               <Button 
                 android:text="@string/download" 
                 android:id="@+id/btnsong1_2" 
                 android:layout_toRightOf="@id/btnsong1_1"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_weight="1">
               </Button>
             </LinearLayout>

...

<!-- song40 -->              
             <TextView
                 android:id="@+id/textView41"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:text="@string/s40" 
                 android:background="#FFFFFF"/>

             <ImageView
                 android:id="@+id/imageView40"
                 android:layout_width="match_parent"
                 android:layout_height="137dp"
                 android:contentDescription="@string/imageView1"
                 android:src="@drawable/zn" />

             <LinearLayout 
                 android:orientation="horizontal"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content">

               <Button 
                 android:text="@string/play" 
                 android:id="@+id/btnsong40_1" 
                 android:layout_width="fill_parent" 
                 android:layout_height="wrap_content"
                 android:layout_weight="1">
               </Button>

               <Button 
                 android:text="@string/download" 
                 android:id="@+id/btnsong40_2" 
                 android:layout_toRightOf="@id/btnsong40_1"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_weight="1">
               </Button>
             </LinearLayout>

<!-- end -->   




        </LinearLayout>

     </ListView>

</LinearLayout>

.java:

package com.example.listentomusic;

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


public class Menu extends Activity {

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);


        Button btnmarch = (Button) findViewById(R.id.btnmarch);
        btnmarch.setOnClickListener(new View.OnClickListener() {


            public void onClick(View v) {
             // TODO Auto-generated catch block
            startActivity(new Intent("android.intent.action.MARCH"));

                } 
        });
    }
}

android manifest:

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

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.listentomusic.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=".Menu"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MENU" />

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

         <activity
            android:name=".About"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.ABOUT" />

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


        <activity 
            android:name=".March"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MARCH" />

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



    </application>

</manifest>
ILikeAndroid
  • 3
  • 2
  • 8

1 Answers1

0

Out of memory:

This is the problem you need to address.

I have a lot of views on 1 layout more than 80 views that's the problem.

Try to reduce the number of views and run I think it will run the issue is the large number of views you are creating in the layout. This will vary from device to device some device might support the huge number of views you have.

I recently encountered a similar problem a layout was working fine on most of the major devices(samsung,motorola,lg) but was crashing on Sony Xperia S.

Sunny Kumar Aditya
  • 2,806
  • 4
  • 26
  • 38
  • i fixed the out of memory but i dont know how to let it work on 80 views i can't reduce it :) – ILikeAndroid Apr 20 '13 at 16:00
  • yes you can your listview implementation needs to be changed. Read these http://www.vogella.com/articles/AndroidListView/article.html && http://www.androidhive.info/2011/10/android-listview-tutorial/ – Sunny Kumar Aditya Apr 20 '13 at 17:07