在LunarLander的Andr​​oid IllegalThreadStateException [英] Android IllegalThreadStateException in LunarLander

查看:76
本文介绍了在LunarLander的Andr​​oid IllegalThreadStateException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚来润色我的申请,并使其恢复用户离开后。当应用程序恢复我得到一个IllegalThreadStateException,这是相当烦人。这个问题是present的例子谷歌给出的月球着陆器 。有没有人找到了一种方法来恢复工作使用surfaceView什么时候?

Just come to polishing my application and making it resume after the user has left. When the application restores I get an IllegalThreadStateException, which is quite annoying. This problem is present in the example google gives of Lunar Lander. Has anyone found a way to restore working when using surfaceView?

推荐答案

我相信这源自于如何在地面和活动都处理的差距。当你离开LunarLander应用表面被销毁(调用surfaceDestroyed),但活动只是暂停(调用的onPause)。当活动重新开始创建面(调用surfaceCreated),它试图重新开始绘图线程。

I believe this arises from a disparity in how the Surface and the Activity are handled. When you leave the LunarLander application the surface is destroyed (invoking surfaceDestroyed) but the Activity is only paused (invoking onPause). When the Activity is resumed the surface is created (invoking surfaceCreated) and it attempts to start the drawing thread again.

这意味着创建线程发生与活动的生命周期和销毁线程发生与SurfaceView的生命周期,这并不一定对应,从而IllegalThreadStateException。该解决方案是配合线程一个生命周期或其他,而不是两个。

This means that creating the Thread happens with the Activity's lifecycle and destroying the thread happens with the SurfaceView's lifecycle, which do not always correspond, thus the IllegalThreadStateException. The solution would be to tie the thread to one lifecycle or the other, not both.

我觉得这个线程提出了一种可能的解决办法,虽然我不知道如果它的工作原理。

I think this thread proposes a possible solution, though I don't know if it works.

这篇关于在LunarLander的Andr​​oid IllegalThreadStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆