触摸的窗口尚未完成某些输入事件的处理(很多时候我都崩溃了,我完全不知道)

时间:2018-11-26 06:41:02

标签: android

这是我的崩溃日志:

2018-11-01 15:24:09.368 3706-3722 /? E / ActivityManager:com.bs.commerce(com.bs.commerce / .MainActivity)中的ANR PID:21171     原因:输入调度超时(等待发送非键事件,因为触摸的窗口尚未完成处理500.0ms之前传送给它的某些输入事件。等待队列长度:8.等待队列头年龄:20667.0ms。)

Load: 4.34 / 4.6 / 3.52
CPU usage from 14871ms to 0ms ago (2018-11-01 15:23:51.186 to 2018-11-01 15:24:06.057):
  100% 21171/com.bs.commerce: 100% user + 0% kernel / faults: 270 minor
  22% 3706/system_server: 12% user + 9.8% kernel / faults: 32277 minor 1378 major
  11% 18962/com.dewmobile.kuaiya.play: 8.5% user + 2.8% kernel / faults: 468 minor 8 major
  9% 4783/com.google.android.gms: 6.7% user + 2.2% kernel / faults: 10036 minor 454 major
  5.9% 4038/com.android.systemui: 4.4% user + 1.4% kernel / faults: 9658 minor 306 major
  4.3% 3154/surfaceflinger: 1.5% user + 2.8% kernel / faults: 205 minor
  0.6% 14475/adbd: 0.1% user + 0.4% kernel / faults: 6455 minor 8 major
  3.3% 4277/com.google.android.gms.persistent: 2.2% user + 1% kernel / faults: 3883 minor 1440 major
  2.8% 943/kswapd0: 0% user + 2.8% kernel
  2.3% 2991/logd: 0.4% user + 1.8% kernel / faults: 1870 minor 1099 major
  0.7% 22499/com.samsung.android.MtpApplication: 0.4% user + 0.2% kernel / faults: 5933 minor 10 major
  1.1% 2975/kworker/4:2: 0% user + 1.1% kernel
  0% 1345/kworker/6:1: 0% user + 0% kernel
  0.2% 4747/com.sec.android.app.launcher: 0.1% user + 0% kernel / faults: 3758 minor 379 major
  0.8% 21987/com.facebook.katana: 0.7% user + 0.1% kernel / faults: 3014 minor 5 major
  0.6% 4954/android.process.media: 0.4% user + 0.2% kernel / faults: 1595 minor 380 major
  0.6% 17509/kworker/0:0: 0% user + 0.6% kernel
  0.6% 22816/com.google.android.instantapps.supervisor: 0.6% user + 0% kernel / faults: 1510 minor 7 major
  0.1% 1965/kworker/5:2: 0% user + 0.1% kernel
  0.5% 3217/kworker/u17:1: 0% user + 0.5% kernel
  0.4% 3153/servicemanager: 0.1% user + 0.3% kernel / faults: 4 minor
  0.4% 4062/wpa_supplicant: 0% user + 0.4% kernel / faults: 54 minor
  0.4% 1833/decon0: 0% user + 0.4% kernel
  0.4% 4218/com.android.phone: 0.2% user + 0.2% kernel / faults: 464 minor 60 major
  0.1% 22339/com.samsung.cmh:CMH: 0.1% user + 0% kernel / faults: 325 minor
  0.1% 3152/lmkd: 0% user + 0.1% kernel
  0.2% 1213/hwrng: 0% user + 0.2% kernel
  0.1% 2983/jbd2/sda17-8: 0% user + 0.1% kernel
  0.1% 4644/com.android.nfc: 0% user + 0% kernel / faults: 1020 minor 91 major
  0.2% 10518/com.android.vending: 0.1% user + 0.1% kernel / faults: 1627 minor 801 major
  0% 13877/com.samsung.android.sm.devicesecurity: 0% user + 0% kernel / faults: 370 minor 35 major
  0.1% 21370/com.google.process.gapps: 0% user + 0% kernel / faults: 1480 minor
  0.2% 627/spi1: 0% user + 0.2% kernel
  0% 3173/zygote64: 0% user + 0% kernel / faults: 424 minor 1 major
  0.1% 7/migration/0: 0% user + 0.1% kernel
  0.1% 23/migration/3: 0% user + 0.1% kernel
  0.1% 1344/kworker/u16:2: 0% user + 0.1% kernel
  0.1% 1383/kworker/u16:6: 0% user + 0.1% kernel
  0.1% 1827/s3c-fb-vsync: 0% user + 0.1% kernel
  0.1% 3199/netd: 0% user + 0% kernel / faults: 243 minor 2 major
  0.1% 3490/kworker/1:6: 0% user + 0.1% kernel
  0% 4656/com.samsung.android.providers.context: 0% user + 0% kernel / faults: 315 minor 54 major
  0.1% 4797/com.google.android.googlequicksearchbox:search: 0% user + 0% kernel / faults: 688 minor 202 major
  0% 22517/com.sec.android.sidesync30: 0% user + 0% kernel / faults: 123 minor
  0% 1//init: 0% user + 0% kernel / faults: 26 minor
  0% 3/ksoftirqd/0: 0% user + 0% kernel
  0% 6/kworker/u16:0: 0% user + 0% kernel
  0% 8/rcu_preempt: 0% user + 0% kernel
  0% 13/migration/1: 0% user + 0% kernel
  0% 18/migration/2: 0% user + 0% kernel
  0% 29/ksoftirqd/4: 0% user + 0% kernel
  0% 31/kworker/4:0H: 0% user + 0% kernel
  0% 34/ksoftirqd/5: 0% user + 0% kernel
  0% 39/ksoftirqd/6: 0% user + 0% kernel
  0% 801/ion_noncontig_h: 0% user + 0% kernel
  0% 1379/kworker/u16:5: 0% user + 0% kernel
  0% 2966/kworker/7:2H: 0% user + 0% kernel
  0% 307

1 个答案:

答案 0 :(得分:1)

我在我的应用中遇到了类似的ANR。当UI被阻止或UI触发代码花费太多时间时,通常会发生这种情况。

更具体地说:

  • 在5秒钟内没有响应输入事件(例如按键或屏幕触摸事件)。

  • BroadcastReceiver尚未在10秒内完成执行。

来源:https://developer.android.com/training/articles/perf-anr.html#anr

如果此问题是可重现的-我会将在UI线程上那时运行的所有代码分成两组:

  1. 必须在UI线程上运行的代码。

  2. 可以移动到后台线程的代码。

然后,当然,我将所有代码从#2移到后台线程中执行,以便可以将UI的控制尽快返回给OS。