I've noticed that if my Activity restarts either due to a crash or due to inactivity my ProgressBar behaves weirdly. Normally my app shows a horizontal progress bar with a max and increments the counter from 0 to max as RSS feeds are loaded. However when the activity is restarted the first increment of the progress immediately takes the progress from 0 to max and stays there until the whole operation is complete.
Here is the relevant section of code:
mProgressBarText.setVisibility(View.VISIBLE);
mProgressBarProgressText.setVisibility(View.VISIBLE);
mProgressBarHorizontal.setVisibility(View.VISIBLE);
mProgressBarHorizontal.setProgress(0);
mProgressBarHorizontal.setMax(feedUrls.length);
mProgressBarProgressText.setText(mProgressBarHorizontal.getProgress() + "/" + feedUrls.length);
FeedUtils.loadFeeds(mContext, feedUrls, new FeedLoader.ProcessingCallback() {
@Override
public void onSuccess() {
displayFeed(null, false, true);
}
@Override
public void onIncrement() {
mProgressBarHorizontal.setProgress(mProgressBarHorizontal.getProgress() + 1);
mProgressBarProgressText.setText(mProgressBarHorizontal.getProgress() + "/" + feedUrls.length);
}
@Override
public void onFailure() {
displayFeed(null, false, true);
}
});
loadFeeds()
spins up Async tasks on a thread pool and uses a CountDownLatch
to track thread task completion and calls either onSuccess
or onFailure
when complete. onIncrement is called in the postExecute
of each Async task. I have checked that the incrementation code is performed on the UI thread and have tried forcing it via runOnUIThread
without luck.
I've seen a few posts about bugs with the Android ProgressBar and have tried what they suggested without success:
Any ideas what I might be doing wrong here?