强制关闭后,pressing home键打开应用程序时, [英] Force Close when opening app after pressing home button
问题描述
我有一个游戏,有surfaceview并在一个线程中运行。 如果我preSS HOME按钮时,游戏的玩,然后我通过图标再次打开游戏,我得到一个强制关闭。有什么问题可能是什么?
I have a game which has surfaceview and running on a thread. if I press HOME button when the game's playing and then I open the game again through the icon, I get a force close. what's the problem might be?
推荐答案
你使用启动发
thread.start()
在 surfaceCreated
回调?如果是这样,就会有如果你没有使用一个包含检查,如果你的游戏已经开始了一个成员变量始终是一个错误。
Do you start your Thread
by using thread.start()
in the surfaceCreated
callback? If so, there will always be an error if you're not using a member variable that contains a check if your game has been started.
您需要暂停的发
在 surfaceDestroyed
回调使用等待( )
命令,所以它不会暂停时重申你的游戏code。你开始你的应用程序(第一次或者第二次),你需要启动()
,或通知()下一次code>这(暂停后),视情况而定。
You need to "pause" your Thread
in the surfaceDestroyed
callback using wait()
command so it doesn't reiterate your game code during pause. Next time you're starting your application (for the first time or maybe second time) you need to start()
it or notify()
it (after pausing) depending on the circumstances.
最后,永远永远张贴code。这将吸引人们正确,正确回答这个问题。
At last, always always post code. That will engage people to answer the question properly and correct.
这篇关于强制关闭后,pressing home键打开应用程序时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!