koral--/android-gif-drawable · error · UnsupportedOperationException

Changing SurfaceTextureListener is not supported

Error message

Changing SurfaceTextureListener is not supported

What it means

GifTextureView overrides setSurfaceTextureListener to deliberately forbid changing the listener, because the view manages its own SurfaceTextureListener internally for GIF rendering. Any call throws UnsupportedOperationException('Changing SurfaceTextureListener is not supported').

Solutions

  1. Remove the setSurfaceTextureListener call — GifTextureView handles its own rendering.
  2. Don't use GifTextureView if you need a custom SurfaceTextureListener; use a plain TextureView plus your own GIF decoding.
  3. Observe rendering via GifTextureView's other APIs (e.g. the underlying GifDrawable callbacks) instead of the listener.

Example fix

// before
gifTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {...});
// after
// removed: GifTextureView manages its own SurfaceTextureListener internally
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(view instanceof GifTextureView)) { view.setSurfaceTextureListener(listener); }

Type guard

boolean supportsListenerChange(View v) { return !(v instanceof GifTextureView); }

Try / catch

try { view.setSurfaceTextureListener(listener); } catch (UnsupportedOperationException e) { /* GifTextureView: use its own APIs instead */ }

Prevention

When it happens

Trigger: Calling gifTextureView.setSurfaceTextureListener(myListener) directly, or indirectly via framework code that sets listeners on TextureView subclasses.

Common situations: Treating GifTextureView as a drop-in TextureView and copying TextureView setup code; UI frameworks or abstractions that programmatically assign surface listeners.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of koral--/android-gif-drawable@26ff795f78 (2026-09-10). Data as JSON: /api/errors/d904549dc61c16d4. Report an issue: GitHub.

Appendix: source

Thrown at android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifTextureView.java:114

			viewAttributes = new GifViewUtils.GifViewAttributes();
		}
		if (!isInEditMode()) {
			mRenderThread = new RenderThread(this);
			if (mInputSource != null) {
				mRenderThread.start();
			}
		}
	}

	/**
	 * Always throws {@link UnsupportedOperationException}. Changing {@link SurfaceTextureListener}
	 * is not supported.
	 *
	 * @param listener ignored
	 */
	@Override
	public void setSurfaceTextureListener(SurfaceTextureListener listener) {
		throw new UnsupportedOperationException("Changing SurfaceTextureListener is not supported");
	}

	/**
	 * Always returns null since changing {@link SurfaceTextureListener} is not supported.
	 *
	 * @return always null
	 */
	@Override
	public SurfaceTextureListener getSurfaceTextureListener() {
		return null;
	}

	/**
	 * Always throws {@link UnsupportedOperationException}. Changing {@link SurfaceTexture} is not
	 * supported.
	 *
	 * @param surfaceTexture ignored
	 */

View on GitHub (pinned to 26ff795f78)