在 Android 上点击按钮需要很长的响应时间
首先,我使用 System.Out.print 输出一些内容,但我在控制台或 logcat 中没有看到它,它在哪里显示?
然后当按下按钮时,需要很长时间才能响应。我从 logcat 记录文件,但不知道操作系统在这背后做了什么,花了这么长时间。
02-16 13:01:07.859: WARN/WindowManager(51): Key dispatching timed out sending to com.test.finalapp/com.test.finalapp.tab.FeaturedActivity
02-16 13:01:08.101: WARN/WindowManager(51): Dispatch state: {{KeyEvent{action=1 code=4 repeat=0 meta=0 scancode=158 mFlags=8} to Window{44dcd868 com.test.finalapp/com.test.finalapp.MyAccount1_1Activity paused=false} @ 1329425383564
lw=Window{44dcd868 com.test.finalapp/com.test.finalapp.MyAccount1_1Activity paused=false} lb=android.os.BinderProxy@44e756f0 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{44e2b0a0 com.test.finalapp/com.test.finalapp.games.slotMachine paused=false}}}
02-16 13:01:08.119: WARN/WindowManager(51): Current state: {{null to Window{44e2c788 com.test.finalapp/com.test.finalapp.tab.FeaturedActivity paused=false} @ 1329426068120 lw=Window{44e2c788 com.test.finalapp/com.test.finalapp.tab.FeaturedActivity paused=false} lb=android.os.BinderProxy@44e2c5a0 fin=true gfw=true ed=true tts=0 wf=false fp=false mcf=Window{44e2b0a0 com.test.finalapp/com.test.finalapp.games.slotMachine paused=false}}}
02-16 13:01:08.240: INFO/ActivityManager(51): ANR in process: com.test.finalapp (last in com.test.finalapp)
02-16 13:01:08.240: INFO/ActivityManager(51): Annotation: keyDispatchingTimedOut
02-16 13:01:08.240: INFO/ActivityManager(51): CPU usage:
02-16 13:01:08.240: INFO/ActivityManager(51): Load: 0.37 / 0.37 / 0.38
02-16 13:01:08.240: INFO/ActivityManager(51): CPU usage from 8216ms to 81ms ago:
02-16 13:01:08.240: INFO/ActivityManager(51): system_server: 4% = 3% user + 1% kernel / faults: 4 minor
02-16 13:01:08.240: INFO/ActivityManager(51): obango.finalapp: 0% = 0% user + 0% kernel
02-16 13:01:08.240: INFO/ActivityManager(51): qemud: 0% = 0% user + 0% kernel
02-16 13:01:08.240: INFO/ActivityManager(51): logcat: 0% = 0% user + 0% kernel
02-16 13:01:08.240: INFO/ActivityManager(51): events/0: 0% = 0% user + 0% kernel
02-16 13:01:08.240: INFO/ActivityManager(51): TOTAL: 5% = 4% user + 1% kernel
02-16 13:01:08.251: INFO/ActivityManager(51): Removing old ANR trace file from /data/anr/traces.txt
02-16 13:01:09.081: INFO/Process(51): Sending signal. PID: 239 SIG: 3
02-16 13:01:09.239: INFO/dalvikvm(239): threadid=7: reacting to signal 3
02-16 13:01:09.458: INFO/Process(51): Sending signal. PID: 51 SIG: 3
02-16 13:01:09.486: INFO/dalvikvm(51): threadid=7: reacting to signal 3
02-16 13:01:10.457: INFO/dalvikvm(239): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:12.037: INFO/dalvikvm(51): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:12.055: INFO/Process(51): Sending signal. PID: 223 SIG: 3
02-16 13:01:12.269: INFO/dalvikvm(223): threadid=7: reacting to signal 3
02-16 13:01:12.358: INFO/Process(51): Sending signal. PID: 213 SIG: 3
02-16 13:01:12.375: INFO/dalvikvm(213): threadid=7: reacting to signal 3
02-16 13:01:12.608: INFO/Process(51): Sending signal. PID: 154 SIG: 3
02-16 13:01:12.885: INFO/Process(51): Sending signal. PID: 146 SIG: 3
02-16 13:01:12.905: INFO/dalvikvm(213): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:13.113: INFO/Process(51): Sending signal. PID: 189 SIG: 3
02-16 13:01:13.348: INFO/Process(51): Sending signal. PID: 181 SIG: 3
02-16 13:01:13.602: INFO/Process(51): Sending signal. PID: 170 SIG: 3
02-16 13:01:13.816: INFO/dalvikvm(146): threadid=7: reacting to signal 3
02-16 13:01:13.976: INFO/dalvikvm(189): threadid=7: reacting to signal 3
02-16 13:01:14.084: INFO/Process(51): Sending signal. PID: 103 SIG: 3
02-16 13:01:14.144: INFO/dalvikvm(103): threadid=7: reacting to signal 3
02-16 13:01:14.342: INFO/Process(51): Sending signal. PID: 106 SIG: 3
02-16 13:01:16.950: INFO/dalvikvm(170): threadid=7: reacting to signal 3
02-16 13:01:18.814: INFO/dalvikvm(181): threadid=7: reacting to signal 3
02-16 13:01:23.204: WARN/MediaPlayer(239): info/warning (1, 44)
02-16 13:01:23.578: DEBUG/AudioSink(30): bufferCount (4) is too small and increased to 12
02-16 13:01:24.137: WARN/AudioFlinger(30): write blocked for 76 msecs, 2 delayed writes, thread 0xb388
02-16 13:01:24.385: DEBUG/dalvikvm(239): GC freed 4564 objects / 281416 bytes in 77ms
02-16 13:01:24.914: INFO/MediaPlayer(239): Info (1,44)
02-16 13:01:25.537: INFO/dalvikvm(106): threadid=7: reacting to signal 3
02-16 13:01:26.370: INFO/dalvikvm(103): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:26.435: INFO/dalvikvm(223): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:27.350: INFO/dalvikvm(170): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:27.611: INFO/dalvikvm(181): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:28.074: INFO/ActivityManager(51): Starting activity: Intent { cmp=com.test.finalapp/.Leaderboard1 (has extras) }
02-16 13:01:28.934: INFO/ActivityManager(51): Displayed activity com.test.finalapp/.Leaderboard1: 754 ms (total 754 ms)
02-16 13:01:29.889: INFO/dalvikvm(189): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:30.152: INFO/dalvikvm(146): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:30.375: INFO/dalvikvm(154): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:31.183: INFO/dalvikvm(106): Wrote stack trace to '/data/anr/traces.txt'
First, I use a System.Out.print to output something but I don't see that in the console or logcat, where does it display?
Then when hit the button, it takes long time to respond. I log the files from logcat and have No idea what the OS is doing behind which took so long.
02-16 13:01:07.859: WARN/WindowManager(51): Key dispatching timed out sending to com.test.finalapp/com.test.finalapp.tab.FeaturedActivity
02-16 13:01:08.101: WARN/WindowManager(51): Dispatch state: {{KeyEvent{action=1 code=4 repeat=0 meta=0 scancode=158 mFlags=8} to Window{44dcd868 com.test.finalapp/com.test.finalapp.MyAccount1_1Activity paused=false} @ 1329425383564
lw=Window{44dcd868 com.test.finalapp/com.test.finalapp.MyAccount1_1Activity paused=false} lb=android.os.BinderProxy@44e756f0 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{44e2b0a0 com.test.finalapp/com.test.finalapp.games.slotMachine paused=false}}}
02-16 13:01:08.119: WARN/WindowManager(51): Current state: {{null to Window{44e2c788 com.test.finalapp/com.test.finalapp.tab.FeaturedActivity paused=false} @ 1329426068120 lw=Window{44e2c788 com.test.finalapp/com.test.finalapp.tab.FeaturedActivity paused=false} lb=android.os.BinderProxy@44e2c5a0 fin=true gfw=true ed=true tts=0 wf=false fp=false mcf=Window{44e2b0a0 com.test.finalapp/com.test.finalapp.games.slotMachine paused=false}}}
02-16 13:01:08.240: INFO/ActivityManager(51): ANR in process: com.test.finalapp (last in com.test.finalapp)
02-16 13:01:08.240: INFO/ActivityManager(51): Annotation: keyDispatchingTimedOut
02-16 13:01:08.240: INFO/ActivityManager(51): CPU usage:
02-16 13:01:08.240: INFO/ActivityManager(51): Load: 0.37 / 0.37 / 0.38
02-16 13:01:08.240: INFO/ActivityManager(51): CPU usage from 8216ms to 81ms ago:
02-16 13:01:08.240: INFO/ActivityManager(51): system_server: 4% = 3% user + 1% kernel / faults: 4 minor
02-16 13:01:08.240: INFO/ActivityManager(51): obango.finalapp: 0% = 0% user + 0% kernel
02-16 13:01:08.240: INFO/ActivityManager(51): qemud: 0% = 0% user + 0% kernel
02-16 13:01:08.240: INFO/ActivityManager(51): logcat: 0% = 0% user + 0% kernel
02-16 13:01:08.240: INFO/ActivityManager(51): events/0: 0% = 0% user + 0% kernel
02-16 13:01:08.240: INFO/ActivityManager(51): TOTAL: 5% = 4% user + 1% kernel
02-16 13:01:08.251: INFO/ActivityManager(51): Removing old ANR trace file from /data/anr/traces.txt
02-16 13:01:09.081: INFO/Process(51): Sending signal. PID: 239 SIG: 3
02-16 13:01:09.239: INFO/dalvikvm(239): threadid=7: reacting to signal 3
02-16 13:01:09.458: INFO/Process(51): Sending signal. PID: 51 SIG: 3
02-16 13:01:09.486: INFO/dalvikvm(51): threadid=7: reacting to signal 3
02-16 13:01:10.457: INFO/dalvikvm(239): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:12.037: INFO/dalvikvm(51): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:12.055: INFO/Process(51): Sending signal. PID: 223 SIG: 3
02-16 13:01:12.269: INFO/dalvikvm(223): threadid=7: reacting to signal 3
02-16 13:01:12.358: INFO/Process(51): Sending signal. PID: 213 SIG: 3
02-16 13:01:12.375: INFO/dalvikvm(213): threadid=7: reacting to signal 3
02-16 13:01:12.608: INFO/Process(51): Sending signal. PID: 154 SIG: 3
02-16 13:01:12.885: INFO/Process(51): Sending signal. PID: 146 SIG: 3
02-16 13:01:12.905: INFO/dalvikvm(213): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:13.113: INFO/Process(51): Sending signal. PID: 189 SIG: 3
02-16 13:01:13.348: INFO/Process(51): Sending signal. PID: 181 SIG: 3
02-16 13:01:13.602: INFO/Process(51): Sending signal. PID: 170 SIG: 3
02-16 13:01:13.816: INFO/dalvikvm(146): threadid=7: reacting to signal 3
02-16 13:01:13.976: INFO/dalvikvm(189): threadid=7: reacting to signal 3
02-16 13:01:14.084: INFO/Process(51): Sending signal. PID: 103 SIG: 3
02-16 13:01:14.144: INFO/dalvikvm(103): threadid=7: reacting to signal 3
02-16 13:01:14.342: INFO/Process(51): Sending signal. PID: 106 SIG: 3
02-16 13:01:16.950: INFO/dalvikvm(170): threadid=7: reacting to signal 3
02-16 13:01:18.814: INFO/dalvikvm(181): threadid=7: reacting to signal 3
02-16 13:01:23.204: WARN/MediaPlayer(239): info/warning (1, 44)
02-16 13:01:23.578: DEBUG/AudioSink(30): bufferCount (4) is too small and increased to 12
02-16 13:01:24.137: WARN/AudioFlinger(30): write blocked for 76 msecs, 2 delayed writes, thread 0xb388
02-16 13:01:24.385: DEBUG/dalvikvm(239): GC freed 4564 objects / 281416 bytes in 77ms
02-16 13:01:24.914: INFO/MediaPlayer(239): Info (1,44)
02-16 13:01:25.537: INFO/dalvikvm(106): threadid=7: reacting to signal 3
02-16 13:01:26.370: INFO/dalvikvm(103): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:26.435: INFO/dalvikvm(223): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:27.350: INFO/dalvikvm(170): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:27.611: INFO/dalvikvm(181): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:28.074: INFO/ActivityManager(51): Starting activity: Intent { cmp=com.test.finalapp/.Leaderboard1 (has extras) }
02-16 13:01:28.934: INFO/ActivityManager(51): Displayed activity com.test.finalapp/.Leaderboard1: 754 ms (total 754 ms)
02-16 13:01:29.889: INFO/dalvikvm(189): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:30.152: INFO/dalvikvm(146): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:30.375: INFO/dalvikvm(154): Wrote stack trace to '/data/anr/traces.txt'
02-16 13:01:31.183: INFO/dalvikvm(106): Wrote stack trace to '/data/anr/traces.txt'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该向我们提供执行的代码,如果您只是调用一个方法,也应该向我们提供该方法的代码。你的system.out将打印在logcat中,只需检查标签
System
即可。即使没有您的代码,我也可以开始一个有根据的猜测:当触摸监听器在 UI 线程上运行时,您的按钮可能会触发长时间操作并阻塞 UI 线程。
您还应该考虑将其移至 AsyncTask 中,该异步任务旨在用于长期操作,例如互联网访问或计算。您也可以从 AsyncTask 轻松更新 UI。
You should give us the code that is executed and, if you just call a method, give us the code of the method, too. Yous system.out will be printed in the logcat, just check for the tag
System
.Even without your code, I can start a educated guess: Your button probably trigger a long taking operation and blocks the UI thread as the touchlistener runs on the UI Thread.
You should also consider moving it into an AsyncTask that is meant to be used for long term operations like internet access or calculations. You can update your UI easily from the AsyncTask, too.