How To Pause A SurfaceView Thread From An Android Activity

故事扮演 提交于 2019-12-12 03:57:01

问题


I have followed this tutorial in great detail and have managed to understand and replicate the functions that I need from an Android SurfaceView:

http://obviam.net/index.php/moving-images-on-the-screen-with-androi/

I need to add a "pause" button in the game, which would be accessed from the activity. How would I go about pausing and then later continuing the thread from the activity?

I have tried adding a button to test it but from that point I can't fathom how to control the thread from the Activity. Any help will be very useful and much appreciated.

Thank you in advance


回答1:


My opinion to you would be not to pause the thread when the virtual pause button in the game has been pressed, yet rather just alter your update method: eg

if(paused == true) {
// Don't do anything 


} 
else {
// Play
}

Yet to pause a your rendering thread, you can invoke the join() method on the thread.

I hope this helps.




回答2:


I figured out a simple way to bypass the problem.

All I did was got the pause button to call an activity over the Surfaceview and hence it would pause the view. Then when I close that activity the thread continues from where it left off.



来源:https://stackoverflow.com/questions/12626112/how-to-pause-a-surfaceview-thread-from-an-android-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!