how to pause and resume a surfaceView thread

前端 未结 8 1276
野趣味
野趣味 2020-12-02 08:21

I have a surfaceView setup and running, but when I resume it I get an error that the thread has already been started. What\'s the proper way to handle when the app goes to t

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 08:41

    The best way I have found is to override the onResume method of the activity controlling the surface view so that with the method it re-instantiates the SurfaceView and then sets it with setContentView. The problem with this approach is that you need to reload any state that your SurfaceView was taking care of.

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(new MyCustomSurfaceView(this));
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            setContentView(new MyCustomSurfaceView(this));
        }
    

提交回复
热议问题