开发者

AsyncTask crashes when used from onSurfaceCreated

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜