{"record":{"id":"c2c564adad5217b9","repo":"material-components/material-components-android","slug":"cannot-change-indeterminate-animation-type-while-t","errorCode":null,"errorMessage":"Cannot change indeterminate animation type while the progress indicator is show in indeterminate mode.","messagePattern":"Cannot change indeterminate animation type while the progress indicator is show in indeterminate mode\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/progressindicator/CircularProgressIndicator.java","lineNumber":215,"sourceCode":"  public int getIndeterminateAnimationType() {\n    return spec.indeterminateAnimationType;\n  }\n\n  /**\n   * Sets the type of indeterminate animation.\n   *\n   * @param indeterminateAnimationType The new type of indeterminate animation.\n   * @see #getIndeterminateAnimationType()\n   * @attr ref\n   *     com.google.android.material.progressindicator.R.styleable#CircularProgressIndicator_indeterminateAnimationType\n   */\n  public void setIndeterminateAnimationType(\n      @IndeterminateAnimationType int indeterminateAnimationType) {\n    if (spec.indeterminateAnimationType == indeterminateAnimationType) {\n      return;\n    }\n    if (visibleToUser() && isIndeterminate()) {\n      throw new IllegalStateException(\n          \"Cannot change indeterminate animation type while the progress indicator is show in\"\n              + \" indeterminate mode.\");\n    }\n    spec.indeterminateAnimationType = indeterminateAnimationType;\n    spec.validateSpec();\n    IndeterminateAnimatorDelegate<ObjectAnimator> animatorDelegate =\n        indeterminateAnimationType == INDETERMINATE_ANIMATION_TYPE_RETREAT\n            ? new CircularIndeterminateRetreatAnimatorDelegate(getContext(), spec)\n            : new CircularIndeterminateAdvanceAnimatorDelegate(spec);\n    getIndeterminateDrawable().setAnimatorDelegate(animatorDelegate);\n    registerSwitchIndeterminateModeCallback();\n    invalidate();\n  }\n\n  /**\n   * Returns the indicator animating direction used in this progress indicator.\n   *\n   * @see #setIndicatorDirection(int)","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/progressindicator/CircularProgressIndicator.java#L197-L233","documentation":"CircularProgressIndicator.setIndeterminateAnimationType throws IllegalStateException when the animation type is changed while the indicator is currently visible to the user and in indeterminate mode. Swapping the animator delegate mid-flight would restart/glitch a running animation, so the API refuses at runtime (a state error, not an argument error).","triggerScenarios":"Calling setIndeterminateAnimationType(CONTAGIOUS/RETREAT vs ADVANCE) while the circular indicator is shown and animating indeterminately; typically right after show() or while it is visible on screen.","commonSituations":"Toggling between retreat and advance animation based on app state (e.g. theme or data-driven) without hiding the indicator first; calling in onResume while a loading spinner is active.","solutions":["Hide() the indicator first, change the type, then show() again","Set indeterminateAnimationType in XML or before the indicator becomes visible","Guard with: if (!indicator.visibleToUser() || !indicator.isIndeterminate()) before switching"],"exampleFix":"// before\nindicator.show()\nindicator.setIndeterminateAnimationType(CircularProgressIndicator.INDETERMINATE_ANIMATION_TYPE_RETREAT)\n// after\nindicator.hide()\nindicator.setIndeterminateAnimationType(CircularProgressIndicator.INDETERMINATE_ANIMATION_TYPE_RETREAT)\nindicator.show()","handlingStrategy":"validation","validationCode":"fun switchIndeterminateType(indicator: CircularProgressIndicator, type: Int) {\n    if (indicator.isShown && indicator.isIndeterminate) indicator.hide()\n    indicator.setIndeterminateAnimationType(type)\n}","typeGuard":null,"tryCatchPattern":"catch (e: IllegalStateException) { Log.w(TAG, \"Cannot switch animation type while shown; hiding first\", e); indicator.hide() }","preventionTips":["Set indeterminateAnimationType before show() or in XML","Hide the indicator before changing animation type","Treat animation-type switching as a setup-time concern"],"tags":["android","material-components","progressindicator","circular","animation","state"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}