The application may be doing too much work on its

2018-12-31 01:49发布

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 free libraries, nothing is showing in the layout screen. The logcat is repeating the following message:

 W/Trace(1378): Unexpected value from nativeGetEnabledTags: 0
 I/Choreographer(1378): Skipped 55 frames!  The application may be doing too much work on its main thread. 

The problem didn't persist and the chart worked when I ran a sample code pertaining to an evaluation copy of a licensed library.

15条回答
不流泪的眼
2楼-- · 2018-12-31 02:32

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.

查看更多
栀子花@的思念
3楼-- · 2018-12-31 02:35

Another common cause of delays on UI thread is SharedPreferences access. When you call a PreferenceManager.getSharedPreferences and other similar methods for the first time, the associated .xml file is immediately loaded and parsed in the same thread.

One of good ways to combat this issue is triggering first SharedPreference load from the background thread, started as early as possible (e.g. from onCreate of your Application class). This way the preference object may be already constructed by the time you'd want to use it.

Unfortunately, sometimes reading a preference files is necessary during early phases of startup (e.g. in the initial Activity or even Application itself). In such cases it is still possible to avoid stalling UI by using MessageQueue.IdleHandler. Do everything else you need to perform on the main thread, then install the IdleHandler to execute code once your Activity have been fully drawn. In that Runnable you should be able to access SharedPreferences without delaying too many drawing operations and making Choreographer unhappy.

查看更多
旧时光的记忆
4楼-- · 2018-12-31 02:36

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.
查看更多
只靠听说
5楼-- · 2018-12-31 02:38

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.

查看更多
弹指情弦暗扣
6楼-- · 2018-12-31 02:40

I too had the same problem.
Mine was a case where i was using a background image which was in drawables.That particular image was of approx 130kB and was used during splash screen and home page in my android app.

Solution - I just shifted that particular image to drawables-xxx folder from drawables and was able free a lot of memory occupied in background and the skipping frames were no longer skipping.

Update Use 'nodp' drawable resource folder for storing background drawables files.
Will a density qualified drawable folder or drawable-nodpi take precedence?

查看更多
荒废的爱情
7楼-- · 2018-12-31 02:42

First read the warning. It says more load on main thread. So what you have to do is just run functions with more work in a thread.

查看更多
登录 后发表回答