简体   繁体   English

Android-该应用程序可能在其主线程上做了大量工作

[英]Android - 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 2 ImageView in a FrameLayout each one, but when I test it with my phone the app goes really slow when it doesnt have any logic cause I didnt touch the java folder. 我是Android的新编程人员,在ADT中的一个非常简单的示例中遇到了问题,每个FrameLayout中只有2个ImageView,但是当我用手机对其进行测试时,如果没有任何逻辑原因,则应用程序会非常慢我没有碰到Java文件夹。

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 这是我的content_main.xml的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 doesnt exists. 我不得不提到,如果我评论两个FrameLayout之一,则该问题不存在。 Thanks in advance. 提前致谢。

EDIT: I also put the 2 images in the folder Drawable (I dont 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 doesnt exists so I paste my images in the Drawable. 编辑:我也将2个图像放在Drawable文件夹中(我不知道这是否会影响),但我在一个教程中看到必须将图像放在Drawable的子文件夹中(mdpi,hdpi,xhdpi,xxhdpi)该子文件夹不存在,所以我将图像粘贴到Drawable中。

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). 您可以做的是尝试为图像创建多种分辨率(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. 您可以将图像的标准尺寸设置为mdpi,并将hdpi,xhdpi,xxhdpi的尺寸分别以1.5、2、3的比例增加。 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. 有时,这甚至可能导致android中的OOM。 one article explaining it. 一篇解释它。

You should check the documentation for AsyncTask and Thread 您应该检查AsyncTaskThread的文档
There is also a very explanatory guide for Main Threads and Worker Threads 对于主线程和辅助线程也有非常说明性的指南

What is happening is that you perform a lot of cpu-consuming processes in the main thread which may cause your main UI thread to hang. 发生的情况是,您在主线程中执行了许多消耗CPU的进程,这可能会导致主UI线程挂起。 A solution to this is to do the whole image processing in a worker thread and to keep the main thread only for the UI interaction. 一种解决方案是在工作线程中进行整个图像处理,并使主线程仅用于UI交互。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 该应用程序可能在其主线程上做了大量工作(Android) - The application may be doing too much work on its main thread, (Android) MapFragment-应用程序可能在其主线程上做过多的工作 - MapFragment - The application may be doing too much work on its main thread 此应用程序可能在其主线程中做过多的工作 - This application may be doing too much work in its main thread android 跳过44帧! 应用程序可能在其主线程上做了太多工作 - android Skipped 44 frames! The application may be doing too much work on its main thread Android gridview图像该应用程序可能在其主线程上做过多的工作 - Android gridview image The application may be doing too much work on its main thread Android Map-跳帧! 该应用程序可能在其主线程上做过多的工作 - Android Map - Skipped frames! The application may be doing too much work on its main thread Android 跳过 602 帧! 应用程序可能在其主线程上做了太多工作 - Android Skipped 602 frames! The application may be doing too much work on its main thread 如何修复“应用程序可能在其主线程上做了太多工作”(Android) - How to fixed “The application may be doing too much work on its main thread” (Android) 该应用程序可能在其主线程上做太多工作。 (Android Studio模拟器和真实电话模拟器) - The application may be doing too much work on its main thread. (android studio emulator and real phone emulator ) 跳过32帧! 该应用程序可能会在其主线程上执行过多的工作,然后执行FATAL EXCEPTION:main - Skipped 32 frames! The application may be doing too much work on its main thread and then FATAL EXCEPTION: main
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM