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