gpt4 book ai didi

如果在处理时单击,Android 模拟器会崩溃

转载 作者:行者123 更新时间:2023-11-29 16:16:43 25 4
gpt4 key购买 nike

我一直在开发 Android 应用程序并在模拟器上对其进行测试。此应用程序的某些部分需要一些处理时间,例如登录,最多可能需要 10 秒。如果应用程序正在处理登录,并且我在模拟器屏幕上的任意位置单击,这将导致应用程序崩溃 -> 将弹出强制关闭/等待窗口,即使我选择等待,此登录过程也永远不会完成。

不知道有没有人遇到过这种情况?我该怎么做才能避免用户在处理过程中点击并使程序崩溃?或者在真手机上这不是问题?

谢谢!

编辑:这确实是一个 UI 线程问题,我正在使用适用于 Android 的 Mono 编写此应用程序,我使用介绍的方法解决了我的问题 Here!

编辑:这是 LOGCAT 消息

1-11 00:38:49.165 W/WindowManager(   59): Key dispatching timed out sending to BadumnaAndroidApi1.BadumnaAndroidApi1/badumnaandroidapi1.Activity1
01-11 00:38:49.165 W/WindowManager( 59): Previous dispatch state: {{KeyEvent{action=1 code=66 repeat=0 meta=0 scancode=28 mFlags=8} to Window{44ed87d0 BadumnaAndroidApi1.BadumnaAndroidApi1/badumnaandroidapi1.Activity1 paused=false} @ 1326241690617 lw=Window{44ed87d0 BadumnaAndroidApi1.BadumnaAndroidApi1/badumnaandroidapi1.Activity1 paused=false} lb=android.os.BinderProxy@4508a900 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{44ed87d0 BadumnaAndroidApi1.BadumnaAndroidApi1/badumnaandroidapi1.Activity1 paused=false}}}
01-11 00:38:49.175 W/WindowManager( 59): Current dispatch state: {{null to Window{44ed87d0 BadumnaAndroidApi1.BadumnaAndroidApi1/badumnaandroidapi1.Activity1 paused=false} @ 1326242329174 lw=Window{44ed87d0 BadumnaAndroidApi1.BadumnaAndroidApi1/badumnaandroidapi1.Activity1 paused=false} lb=android.os.BinderProxy@4508a900 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{44ed87d0 BadumnaAndroidApi1.BadumnaAndroidApi1/badumnaandroidapi1.Activity1 paused=false}}}
01-11 00:38:49.276 I/Process ( 59): Sending signal. PID: 316 SIG: 3
01-11 00:38:49.276 I/dalvikvm( 316): threadid=3: reacting to signal 3
01-11 00:38:49.485 I/dalvikvm( 316): Wrote stack traces to '/data/anr/traces.txt'
01-11 00:38:49.485 I/Process ( 59): Sending signal. PID: 59 SIG: 3
01-11 00:38:49.485 I/dalvikvm( 59): threadid=3: reacting to signal 3
01-11 00:38:49.595 I/dalvikvm( 59): Wrote stack traces to '/data/anr/traces.txt'
01-11 00:38:49.616 I/Process ( 59): Sending signal. PID: 114 SIG: 3
01-11 00:38:49.616 I/dalvikvm( 114): threadid=3: reacting to signal 3
01-11 00:38:49.625 I/dalvikvm( 114): Wrote stack traces to '/data/anr/traces.txt'
01-11 00:38:49.636 I/Process ( 59): Sending signal. PID: 107 SIG: 3
01-11 00:38:49.645 I/dalvikvm( 107): threadid=3: reacting to signal 3
01-11 00:38:49.655 I/dalvikvm( 107): Wrote stack traces to '/data/anr/traces.txt'
01-11 00:38:49.673 I/Process ( 59): Sending signal. PID: 254 SIG: 3
01-11 00:38:49.865 I/dalvikvm( 254): threadid=3: reacting to signal 3
01-11 00:38:49.875 I/Process ( 59): Sending signal. PID: 246 SIG: 3
01-11 00:38:49.906 I/dalvikvm( 246): threadid=3: reacting to signal 3
01-11 00:38:50.085 I/Process ( 59): Sending signal. PID: 177 SIG: 3
01-11 00:38:50.115 I/dalvikvm( 177): threadid=3: reacting to signal 3
01-11 00:38:50.285 I/Process ( 59): Sending signal. PID: 221 SIG: 3
01-11 00:38:50.345 I/dalvikvm( 221): threadid=3: reacting to signal 3
01-11 00:38:50.495 I/Process ( 59): Sending signal. PID: 169 SIG: 3
01-11 00:38:50.575 I/dalvikvm( 169): threadid=3: reacting to signal 3
01-11 00:38:50.695 I/Process ( 59): Sending signal. PID: 185 SIG: 3
01-11 00:38:50.735 I/dalvikvm( 185): threadid=3: reacting to signal 3
01-11 00:38:50.905 I/Process ( 59): Sending signal. PID: 111 SIG: 3
01-11 00:38:50.905 I/dalvikvm( 111): threadid=3: reacting to signal 3
01-11 00:38:51.065 I/dalvikvm( 111): Wrote stack traces to '/data/anr/traces.txt'
01-11 00:38:51.065 I/Process ( 59): Sending signal. PID: 205 SIG: 3
01-11 00:38:51.185 I/dalvikvm( 205): threadid=3: reacting to signal 3
01-11 00:38:51.275 I/Process ( 59): Sending signal. PID: 194 SIG: 3
01-11 00:38:51.405 I/dalvikvm( 194): threadid=3: reacting to signal 3
01-11 00:38:51.485 I/Process ( 59): Sending signal. PID: 155 SIG: 3
01-11 00:38:51.605 I/dalvikvm( 155): threadid=3: reacting to signal 3
01-11 00:38:51.685 I/Process ( 59): Sending signal. PID: 149 SIG: 3
01-11 00:38:51.875 I/dalvikvm( 149): threadid=3: reacting to signal 3
01-11 00:38:51.885 I/Process ( 59): Sending signal. PID: 115 SIG: 3
01-11 00:38:51.916 I/dalvikvm( 115): threadid=3: reacting to signal 3

最佳答案

好吧,您可能可能会由于这种繁重的处理而导致 UI 线程挂起 - 但我可能会在看不到任何代码的情况下离开 - 提示 -。您可能是将繁重的内容放入独立于您当前运行的 GUI 线程的后台线程中。

幸运的是 Android 有 AsyncTask类在这里帮助你。可以说(因为问题中没有足够的细节)您正在通过向服务器发出网络请求来登录您的应用程序。当用户按下登录时,您希望在后台线程中完成所有跑腿工作时显示某种处理消息。

看看这篇文章,特别是 AsyncTask 示例 http://www.vogella.de/articles/AndroidPerformance/article.html

您可以看到 doInBackground() 是完成所有繁重工作的地方,而 postExecute() 再次在 UI 线程中运行,这是您要根据刚刚发生的结果更新 UI 的地方。例如用户登录成功或登录过程中出现错误。

我可以继续讲很长一段时间,但这有据可查。可以在这里找到 Google 自己的另一篇好文章 http://android-developers.blogspot.com/2009/05/painless-threading.html

关于如果在处理时单击,Android 模拟器会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8812281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com