summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lucas Dupin <dupin@google.com> 2017-04-14 19:47:23 -0700
committer Lucas Dupin <dupin@google.com> 2017-04-18 10:01:34 -0700
commit0c207340b9aaf005da21b15c984e73eec8efacde (patch)
tree16852efa16343f3da21132bb6167c6677daaca40
parentd210ce63d00aa76ec680781bcee08543cc839e66 (diff)
Fix for SurfaceView out of a view hierarchy
At most of the time, developers rely on GLSurfaceView to manage the OpenGL lifecycle. This means that a SurfaceView might not always have a ViewRootImpl. Test: select timelapse wallpaper and set it. Bug: 37363390 Change-Id: I3cdb1ec2a6e91cfad65fd823a7436f0010c0859c
-rw-r--r--core/java/android/view/SurfaceView.java10
1 files changed, 9 insertions, 1 deletions
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index 1a71679449a4..9d40895f6ad9 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -295,7 +295,15 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
@Override
protected void onDetachedFromWindow() {
- getViewRootImpl().removeWindowStoppedCallback(this);
+ ViewRootImpl viewRoot = getViewRootImpl();
+ // It's possible to create a SurfaceView using the default constructor and never
+ // attach it to a view hierarchy, this is a common use case when dealing with
+ // OpenGL. A developer will probably create a new GLSurfaceView, and let it manage
+ // the lifecycle. Instead of attaching it to a view, he/she can just pass
+ // the SurfaceHolder forward, most live wallpapers do it.
+ if (viewRoot != null) {
+ viewRoot.removeWindowStoppedCallback(this);
+ }
mAttachedToWindow = false;
if (mGlobalListenersAdded) {