Reputation: 4069
I have an async task in doInBackround I do all kind of stuff, after various sections I run a
onProgressUpdate("You proceeded a bit further 1/5");
That works fine a multiple times until (still all in doInBackground) I have
HttpSessionToken = (HttpURLConnection)new URL("http://myserver").openConnection();
HttpSessionToken.setRequestMethod("GET");
HttpSessionToken.setRequestProperty("Accept", "application/json");
onProgressUpdate("Still everything is working fine");
int returnCode = HttpSessionToken.getResponseCode();
onProgressUpdate("This onProgressUpdate crashes!");
so the last onProgressUpdate crashes, but why does it crash? Did the getResponseCode() switch the thread I am running on?
Upvotes: 2
Views: 1099
Reputation: 39836
you don't call directly the onProgressUpdate
, you have to call publishProgress
and let the AsynTask framework to handle the onProgressUpdate
to be called back on the UI thread.
Upvotes: 3