Run SurfaceView off UI Thread

2019-03-01 01:42发布

问题:

My surfraceview is where the majority of my application is and I would like to reduce its lag, thus I have been told to take it off the UI Thread. Is it possible to run a SurfaceView in an AsyncTask?

回答1:

While it is possible to draw into a SurfaceView from an AsyncTask it is not recommended. AsyncTasks can run in a serial queue so you would likely block other tasks. Instead just use a Thread. The SDK contains a sample app called LunarLander which shows how to do this.