SurfaceCreated () not called SurfaceView Components

Sometimes we need to do rendering in the context of the surfaceview in the native layer. At this time, we just provide a separate do nothing Surfaceview.

The xml file is as follows:

 

< span style="white-space:pre">

The surfaceview file is as follows:

public class MirrorSurfaceView extends SurfaceView impl ements Runnable, SurfaceHolder.Callback {public MirrorSurfaceView(Context context, AttributeSet attrs) {super(context, attrs);} @Override public void run() {while(true){ if(getHolder().getSurface().isValid( )){ //Canvas canvas = getHolder().lockCanvas(); renderFrame(this.getHolder().getSurface()); //getHolder().unlockCanvasAndPost(canvas);}}} @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {// TODO Auto-generated method stub} @Override public void surfaceCreated(SurfaceHolder holder) {initRender(this.getWidth(), this.getHeight()); new Thread(this ).start();} @Override public void surfaceDestroyed(SurfaceHolder holder) {// TODO Auto-generated method stub} private native void initRender(int render_width, int render_height); private native void renderFrame(Surface surface);}  

is because the java layer thinks that the surfaceview has not done anything, so it will not do any initialization operation, that is, surfaceCreated() will not be called. How to solve this time?

There are two solutions:

< /span>1. Manually add a child control in surfaceview to trigger surfaceview to do lazy initialization. But doing this is sometimes because all of my rendering logic is native, and some are muddy and dirty.

2. Adding this sentence in the surfaceview constructor can also be solved:

getHolder().addCallback(this);

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1511 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.