Called From Wrong Thread Exception

前端 未结 2 1790
执笔经年
执笔经年 2021-01-27 10:53

I am getting an exception here when I try to bring another view to the front. It happens in the last method of my BoardView class where it says if(lives == 0). Can anybody see w

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-27 11:29

    You must update the View using the UI thread (not the SurfaceView thread). If you would like to make some View change from within the SurfaceView thread you must create a new RunOnUiThread which performs the View updating.

    // From within SurfaceView thread
    new Thread() {
        public void run() {
            activity.runOnUiThread(new Runnable() {     
                @Override
                public void run() {
                    // Update view here
                }
            });
        }
    }.start();
    

提交回复
热议问题