使用模拟器时keyDispatchingTimedOut

时间:2011-02-11 03:57:31

标签: java android performance android-emulator

使用蜂窝模拟器时显示以下错误并变得非常慢。

02-11 02:58:50.949: ERROR/ActivityManager(365): ANR in com.android.launcher (com.android.launcher/com.android.launcher2.Launcher)
02-11 02:58:50.949: ERROR/ActivityManager(365): Reason: keyDispatchingTimedOut
02-11 02:58:50.949: ERROR/ActivityManager(365): Load: 2.57 / 1.18 / 0.89
02-11 02:58:50.949: ERROR/ActivityManager(365): CPU usage from 3042ms to -7585ms ago:
02-11 02:58:50.949: ERROR/ActivityManager(365):   74% 365/system_server: 53% user + 21% kernel / faults: 335 minor
02-11 02:58:50.949: ERROR/ActivityManager(365):   9% 780/zygote: 3.8% user + 5.1% kernel / faults: 915 minor
02-11 02:58:50.949: ERROR/ActivityManager(365):   8.2% 684/com.android.launcher: 6% user + 2.1% kernel / faults: 51 minor
02-11 02:58:50.949: ERROR/ActivityManager(365):   0% 432/zygote: 0% user + 0% kernel / faults: 22 minor
02-11 02:58:50.949: ERROR/ActivityManager(365):   2.4% 41/adbd: 0.3% user + 2% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):   0.4% 546/com.android.systemui: 0.1% user + 0.2% kernel / faults: 11 minor
02-11 02:58:50.949: ERROR/ActivityManager(365):   0.5% 733/logcat: 0% user + 0.5% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):   0% 425/zygote: 0% user + 0% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):   0% 28/servicemanager: 0% user + 0% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365): 100% TOTAL: 65% user + 34% kernel + 0.6% softirq
02-11 02:58:50.949: ERROR/ActivityManager(365): CPU usage from 9680ms to 11220ms later:
02-11 02:58:50.949: ERROR/ActivityManager(365):   70% 365/system_server: 28% user + 42% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):     49% 396/InputDispatcher: 18% user + 30% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):     21% 366/HeapWorker: 8.1% user + 13% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):   26% 78014% user + 11% kernel / faults: 323 minor
02-11 02:58:50.949: ERROR/ActivityManager(365):     20% 780/.ap: 10% user + 10% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):     5.4% 781/HeapWorker: 4.6% user + 0.7% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):   1.3% 41/adbd: 0% user + 1.3% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):     0.6% 41/adbd: 0% user + 0.6% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):     0.6% 65/adbd: 0% user + 0.6% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):   0.7% 684/com.android.launcher: 0.7% user + 0% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):     0.7% 684/ndroid.launcher: 0.7% user + 0% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365):     0.7% 691/Binder Thread #: 0.7% user + 0% kernel
02-11 02:58:50.949: ERROR/ActivityManager(365): 100% TOTAL: 40% user + 58% kernel + 0.6% softirq

这里出了什么问题。我需要解决这个问题吗? 谢谢

4 个答案:

答案 0 :(得分:2)

这实际上是ANR (Activity not responding)

您的活动花了足够长的时间来执行您提供的任务

以下链接包含有关如何强制通过THREADS进行回复的信息。

您应该在单独的THREADAsync Task

中执行繁重的日志运行任务

Simlar Problen in SO with solution Here

Here

答案 1 :(得分:1)

  • 1)您可能使用过thread.sleep() 在你的UI线程中。那不酷 和android只是踢你的活动。

  • 2)你在UI线程中做了一些大规模的坏人计算。使用AsyncTask或线程。

  • 3)模拟器有时比手机慢。

答案 2 :(得分:1)

此错误是因为您的avd需要很长时间才能运行Activity

http://developer.android.com/training/articles/perf-anr.html

如果您在UI线程中执行了任何复杂任务,您的应用程序将变得非常慢。要解决此问题,您可以使用painless threadpainless thread

取自Blundell的回答。

我希望这会对你有所帮助。

答案 3 :(得分:0)

似乎您在加载活动时正在进行一些复杂的计算。

ANR(Activity Not Responding)

如果Activity无法告诉Android操作系统"我还活着",通常会触发ANR。 android Developer

您需要以异步方式执行。 所以对于一个实例,如果你想做一些漫长的等待过程onClick()

public void onClick(View v) {
  new DownloadImageTask().execute("http://example.com/image.png");// Any time Taking Event.
}

private class DownloadImageTask extends AsyncTask {
     protected Bitmap doInBackground(String... urls) {
         return loadImageFromNetwork(urls[0]);
     }

     protected void onPostExecute(Bitmap result) {
         mImageView.setImageBitmap(result);
     }
 }