Is It Necessary To Use A Separate Thread When Using Surfaceview?
In Android, I am using a SurfaceView. It is inside a FrameLayout, to draw a couple of things on a transparent layer over the top of a general XML layout (with standard textViews, b
Solution 1:
You don't need to have a separate thread, but it's often a good idea.
For example, take a look at Grafika's "multi-surface test" Activity. It has three overlapping SurfaceViews that are rendered from the UI thread. If you click on the "bounce" button, it starts a new thread to control the animation, because it's simpler to do that way (it can sit in a loop and draw, instead of having to post timed draw events to the UI looper). The bounce thread stops when the Activity is paused. Note the code doesn't do anything in surfaceDestroyed()
.
The interaction between SurfaceView and the Activity lifecycle can be tricky. A discussion can be found here.
(It can be tricky to get everything right.)
Post a Comment for "Is It Necessary To Use A Separate Thread When Using Surfaceview?"