Reputation: 9366
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;
}
@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?
Upvotes: 3
Views: 499
Reputation: 34149
I think you need to call it on the UI thread. Try passing in the context and do runOnUIThread.
Upvotes: 3