AndreiBogdan
AndreiBogdan

Reputation: 11164

How to be sure Progress Bar is stopped

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?

Upvotes: 3

Views: 440

Answers (1)

CoolMind
CoolMind

Reputation: 28793

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.

Upvotes: 3

Related Questions