开发者

AsyncTask crashes when used from onSurfaceCreated

开发者 https://www.devze.com 2023-01-28 18:01 出处:网络
I have a class that extends GLSurfaceView and implements Renderer in my android app that takes care of the opengl rendering.When I try to execute an asynctask from the onSurfaceCreated event, the appl

I have a class that extends GLSurfaceView and implements Renderer in my android app that takes care of the opengl rendering. When I try to execute an asynctask from the onSurfaceCreated event, the application crashes (no exceptions thrown). If run the same async task from the main activity everything is fine. The asynctask implementation is at this point just a place holder:

public class DownloadImageTask extends AsyncTask<String, Void, Integer>
{
        @Override
        protected Integer doInBackground(String... myParams) {
            return 1;
         }

   开发者_JAVA技巧     @Override
        protected void onPostExecute(Integer result)
        {

        }
     }

being called from onSurfaceCreated()

new DownloadImageTask().execute("myParam");

Why can't I start an AsyncTask from the onSurfaceCreated event?


I think you need to call it on the UI thread. Try passing in the context and do runOnUIThread.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号