Issue
Here is my problem. I have noticed that my AsyncTask
does not work properly. What I mean is, even if I run this code:
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
progress.setText(values[0] + "%");
}
@Override
protected Void doInBackground(Void... voids) {
for (i = 0; i <= 100; ++i) {
publishProgress(i);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.i("progress", i + "");
}
return null;
}
it does not seem to do antything at all and after 5 seconds (or even more) my progress alomost instantly goes from 0 to 100%, even though it should wait for 10ms between every call of publishProgress(). Is it something that I'm missing?
Solution
What I think is a thread problem , because AsyncTask automatically creates a new Thread for you, so everything you do in doInBackground() is on another thread. So start "sleep" onPreExecute() and finish onPostExecute()
Answered By - Stavro Xhardha
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.