class MyAsyncTask extends AsyncTask<Void, Integer, Void>{ @Override protected Void doInBackground(Void... params) { for(int i=0;i<100;i++){ publishProgress(i); try { Thread.sleep(300); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; } @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); pb.setProgress(values[0]); } }