From 2dedafb48f85e34a2f48262f12908866fc9de132 Mon Sep 17 00:00:00 2001 From: John Reck Date: Thu, 29 May 2014 16:15:41 -0700 Subject: Fix NPE in onVisibilityChanged Bug: 15089790 onVisibilityChanged may happen before the View is attached. Only attempt to re-set the update listener if mLayer is not null, as it means the View is attached and has already drawn once. If mLayer is null then the update listener will be set when the view next draws Change-Id: I406e359a0a0720988f026f9cbde26afdb564ca92 --- core/java/android/view/TextureView.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'core/java/android') diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java index 1765c43..2a9f7d5 100644 --- a/core/java/android/view/TextureView.java +++ b/core/java/android/view/TextureView.java @@ -405,7 +405,9 @@ public class TextureView extends View { // To cancel updates, the easiest thing to do is simply to remove the // updates listener if (visibility == VISIBLE) { - mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler); + if (mLayer != null) { + mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler); + } updateLayerAndInvalidate(); } else { mSurface.setOnFrameAvailableListener(null); -- cgit v1.1