I’m trying to update the progress bar in a AsyncTask while downloading some stuff..
Here is the code:
@Override
protected void onPreExecute() {
Intent myIntent = new Intent(mContext, Explanation.class);
mContext.startActivity(myIntent);
View inflater = View.inflate(mContext, R.layout.explanation, null);
mProgressDialog = (ProgressBar) inflater.findViewById(R.id.Explanation_ProgressBar);
}
@Override
protected void onProgressUpdate(Integer... values) {
mProgressDialog.setProgress(values[0]);
}
xml:
<ProgressBar
android:max="100"
style="?android:attr/progressBarStyleHorizontal"
android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:id="@+id/Explanation_ProgressBar"
android:layout_height="wrap_content"></ProgressBar>
A note: The progress bar is in the layout of the Activity I call in the onPreExecute(). and I want to update it through the AsyncTask. Is this possible? Why isnt it updated?
To update progress dialog you need to call
publishProgress(...)fromdoInBackground.Check Usage and publishProgress sections of AsyncTask doc