Ushal Naidoo
Ushal Naidoo

Reputation: 2744

How To Pause A SurfaceView Thread From An Android Activity

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

Upvotes: 0

Views: 1187

Answers (2)

Ushal Naidoo
Ushal Naidoo

Reputation: 2744

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.

Upvotes: 0

Luke Taylor
Luke Taylor

Reputation: 9599

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.

Upvotes: 1

Related Questions