简体   繁体   English

检测ui线程在Android上停滞的简单方法?

[英]Easy way to detect where ui thread is stalling on Android?

I have taken over an Android project from a past employee and am wondering if there is an easy tool to use for profiling an Android application. 我接管了一位前任员工的Android项目,我想知道是否有一个简单的工具可用于分析Android应用程序。 I have a LinearLayout with a ProgressBar spinner inside of it. 我有一个带有ProgressBar微调器的LinearLayout。 Now I am running a network call on a different thread while that spinner is showing. 现在我在显示微调器的同时在不同的线程上运行网络调用。 I use a translate animation to show the entire LinearLayout and when the network call returns on the other thread I hide the LinearLayout. 我使用翻译动画来显示整个LinearLayout,当网络调用在另一个线程上返回时,我隐藏了LinearLayout。 Now this works great but I see that the spinner kind of stops spinning while it is showing. 现在这很好用,但我看到旋转器在显示时会停止旋转。 Now it kind of looks like if I interact with the screen, such as trying to scroll, the spinner will continue to spin. 现在看起来如果我与屏幕交互,例如尝试滚动,旋转器将继续旋转。 For a standard ProgressBar spinner do I need to set some command on the spinner to keep it spinning? 对于标准的ProgressBar微调器,我是否需要在微调器上设置一些命令以保持旋转? Any information on this would be great. 有关这方面的任何信息都会很棒。

Thanks 谢谢

您可以使用StrictMode来检测在UI线程上执行的昂贵调用。

Why not try implementing your network call in an AsyncTask ? 为什么不尝试在AsyncTask中实现网络调用? In the onPostExecute method implementation you can do whatever is necessary on the UI (ie hide your progressBar, etc.). onPostExecute方法实现中,您可以在UI上执行任何必要的操作(即隐藏progressBar等)。

Or, if you are using the compatibility / support library , or targeting Honeycomb or later, use a Loader instead. 或者,如果您使用兼容性/支持库 ,或以Honeycomb或更高版本为目标,请改用加载程序

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM