Search code examples
androidbitmapsurfaceviewsurfaceholder

How to update SurfaceView from another Thread?


I have a thread where I will get some Bitmap one by one. Then whenever I get a new Bitmap I need to update my SurfaceView which in the main thread. How can I do this?


Solution

  • Here is some pseudo code

    new Thread() {
        public void run() {
            while (bitmapIncoming()) {
                Bitmap bitmap = getNextBitmapAfterLongOperation();
                mActivityReference.runOnUiThread(new Runnable() {
                    public void run() {
                        mActivityReference.updateSurfaceView(bitmap);
                    }
                });
            }
        }
    }.start();