How to be sure Progress Bar is stopped

Viewed 196

I know that to "stop" the ProgressBar one needs to set its visibility to View.GONE. But ... does that really stop it? There's an animation going in the background that animates the view. Is that animation stopping once it detects the progress bar is GONE or INVISIBILE? I really don't want to have a progress bar continuously running in the background, when not needed. It's a waste of processing power.

Does anyone have any idea?

1 Answers

Looking at ProgressBar.java I found:

/**
 * Returns whether the ProgressBar is animating or not. This is essentially the same
 * as whether the ProgressBar is {@link #isIndeterminate() indeterminate} and visible,
 * as indeterminate ProgressBars are always animating, and non-indeterminate
 * ProgressBars are not animating.
 *
 * @return true if the ProgressBar is animating, false otherwise.
 */
public boolean isAnimating() {
    return isIndeterminate() && getWindowVisibility() == VISIBLE && isShown();
}

void startAnimation() {
    if (getVisibility() != VISIBLE || getWindowVisibility() != VISIBLE) {
        return;
    }
    ...


@Override
protected void onDetachedFromWindow() {
    if (mIndeterminate) {
        stopAnimation();
    }
    ...

I think, ProgressBar will stop animating after you hide it.

Related