Called From Wrong Thread Exception

前端 未结 2 1767
执笔经年
执笔经年 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();
    
    0 讨论(0)
  • 2021-01-27 11:43

    You need to run the bring to front on the right thread. Try this:

    final View v = ((BoardView) getParent()).findViewById(1);
    v.post(new Runnable(){ public void run(){ v.bringToFront(); } });
    

    See if that works.

    0 讨论(0)
提交回复
热议问题