Search code examples
javaandroidxmladt

Android error "The application may be doing too much work on its main thread"


I am new programming with Android and I am having problems with a very simple example in ADT. I only have two ImageView in a FrameLayout each one, but when I test it with my phone the app goes really slow when it doesn't have any logic because I didn't touch the java folder.

This is the error I get in

12-16 16:17:43.261 18238-18238/com.example.brank.acocinapp I/Choreographer: Skipped 64 frames!  The application may be doing too much work on its main thread.
12-16 16:17:44.781 18238-18248/com.example.brank.acocinapp W/art: Suspending all threads took: 26.044ms
12-16 16:17:44.831 18238-18238/com.example.brank.acocinapp W/PathParser: Points are too far apart 4.000000596046461

This is the xml of my content_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.brank.acocinapp.MainActivity">

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/frameLayout2"
        android:layout_alignParentBottom="true">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/imageView3"
            android:adjustViewBounds="true"
            android:src="@drawable/home2" />
    </FrameLayout>


    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/frameLayout"
        android:layout_alignParentTop="true">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/imageView2"
            android:src="@drawable/home1"
            android:adjustViewBounds="true"/>

    </FrameLayout>


</RelativeLayout>

I have to mention that if I comment one of the two FrameLayout the problem doesn't exists.

Edit

I also put the two images in the folder Drawable (I don't know if this affect) but I saw in a tutorial that I have to put the images in the subfolder in Drawable (mdpi, hdpi, xhdpi, xxhdpi) the thing is that this subfolders doesn't exists so I paste my images in the Drawable.


Solution

  • Ok what might be happening is that the OS is trying to do a lot of processing on your images, which you may have chosen of a high resolution. What you can do is try to create multiple resolution of your image (mdpi,hdpi,xhdpi,xxhdpi). you can take the standard size of the image as mdpi and increase their sizes in the ratio of 1.5,2,3 respectively for hdpi,xhdpi,xxhdpi. when you have these images put them in the drawable folders if you don't have them create them by yourself. Sometimes this may even cause OOM's in android. one article explaining it.