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

前端 未结 17 1702
挽巷
挽巷 2020-11-21 07:34

I am new to Android SDK/API environment. It\'s the first I am trying to draw a plot/chart. I tried running different kinds of sample codes the emulator using 3 different fre

相关标签:
17条回答
  • 2020-11-21 08:18

    Try to use the following strategies in order to improve your app performance:

    • Use multi-threading programming if possible. The performance benefits are huge, even if your smart phone has one core (threads can run in different cores, if the processor has two or more). It's useful to make your app logic separated from the UI. Use Java threads, AsyncTask or IntentService. Check this.
    • Read and follow the misc performance tips of Android development website. Check here.
    0 讨论(0)
  • 2020-11-21 08:18

    I am not an expert, but I got this debug message when I wanted to send data from my android application to a web server. Though I used AsyncTask class and did the data transfer in background, for getting the result data back from server I used get() method of the AsyncTask class which makes the UI synchronous which means that your UI will be waiting for too long. So my advice is to make your app do every network oriented tasks on a separate thread.

    0 讨论(0)
  • 2020-11-21 08:18

    I had the same problem. When I ran the code on another computer, it worked fine. On mine, however, it displayed "The application may be doing too much work on its main thread".

    I solved my problem by restarting Android studio [File -> Invalidated caches / Restart -> click on "Invalidate and Restart"].

    0 讨论(0)
  • 2020-11-21 08:22

    I had the same problem. Android Emulator worked perfectly on Android < 6.0. When I used emulator Nexus 5 (Android 6.0), the app worked very slow with I/Choreographer: Skipped frames in the logs.

    So, I solved this problem by changing in Manifest file hardwareAccelerated option to true like this:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.myapplication">
    
        <application android:hardwareAccelerated="true">
            ...
        </application>
    </manifest>
    
    0 讨论(0)
  • 2020-11-21 08:24

    I had the same problem. In my case I had 2 nested Relative Layouts. RelativeLayout always has to do two measure passes. If you nest RelativeLayouts, you get an exponential measurement algorithm.

    0 讨论(0)
提交回复
热议问题