我是Android SDK/API环境的新手。这是我第一次试着画一个图表。我尝试在模拟器上使用3个不同的免费库运行不同种类的示例代码,没有显示在布局屏幕上。日志猫正在重复如下信息:

 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. 

当我运行一个与授权库的评估副本相关的示例代码时,这个问题并没有持续存在,图表也正常工作。


当前回答

this usually happens when you are executing huge processes in main thread. it's OK to skip frames less than 200. but if you have more than 200 skipped frames, it can slow down your application UI thread. what you can do is to do these processes in a new thread called worker thread and after that, when you want to access and do something with UI thread(ex: do something with views, findView etc...) you can use handler or runOnUiThread(I like this more) in order to display the processing results. this absolutely solves the problem. using worker threads are very useful or even must be used when it comes to this cases.

https://stacklearn.ir

其他回答

我不是专家,但当我想从我的android应用程序发送数据到web服务器时,我得到了这个调试消息。虽然我使用AsyncTask类并在后台进行数据传输,但为了从服务器获取结果数据,我使用了AsyncTask类的get()方法,这使得UI同步,这意味着你的UI将等待太长时间。所以我的建议是让你的应用程序在一个单独的线程上执行每个面向网络的任务。

this usually happens when you are executing huge processes in main thread. it's OK to skip frames less than 200. but if you have more than 200 skipped frames, it can slow down your application UI thread. what you can do is to do these processes in a new thread called worker thread and after that, when you want to access and do something with UI thread(ex: do something with views, findView etc...) you can use handler or runOnUiThread(I like this more) in order to display the processing results. this absolutely solves the problem. using worker threads are very useful or even must be used when it comes to this cases.

https://stacklearn.ir

我在开发一个在网格布局上使用大量可绘制png文件的应用程序时遇到了同样的问题。我也尽量优化我的代码。但这对我来说行不通。然后我尝试减小这些png的大小。我猜它工作得绝对很好。所以我的建议是减少可绘制资源的大小。

在这个问题上做了很多研究之后,我得到了解决方案,

在我的情况下,我使用的服务将运行每2秒和runonUIThread,我想知道问题是在那里,但根本没有。 我发现的下一个问题是我在五月的应用程序中使用大图像,这就是问题所在。

我删除了图像,并设置了新的图像。

结论:-检查你的代码是否有任何你正在使用的原始文件是大的。

UI线程延迟的另一个常见原因是SharedPreferences访问。当你调用PreferenceManager。getSharedPreferences和其他类似的方法,关联的.xml文件将立即在同一个线程中加载和解析。

解决这个问题的一个好方法是从后台线程触发第一次SharedPreference加载,越早越好(例如从你的Application类的onCreate开始)。这样,在您想要使用首选项对象时,首选项对象可能已经构造好了。

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.