OSDN Git Service

Fix NPE when detached View is added as a shared element.
authorGeorge Mount <mount@google.com>
Wed, 24 Sep 2014 14:31:45 +0000 (07:31 -0700)
committerGeorge Mount <mount@google.com>
Wed, 24 Sep 2014 19:39:08 +0000 (12:39 -0700)
Bug 17632940

This won't solve all problems in which the parent becomes null,
but it will protect against shared elements being added that aren't
attached when mapped.

Change-Id: I991722c671c57048aea84b59a3c187c77c93450f

core/java/android/app/ActivityTransitionCoordinator.java

index 540376e..5455a0f 100644 (file)
@@ -222,8 +222,15 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver {
         if (mListener != null) {
             mListener.onMapSharedElements(mAllSharedElementNames, sharedElements);
         }
-        mSharedElementNames.addAll(sharedElements.keySet());
-        mSharedElements.addAll(sharedElements.values());
+        int numSharedElements = sharedElements.size();
+        for (int i = 0; i < numSharedElements; i++) {
+            View sharedElement = sharedElements.valueAt(i);
+            String name = sharedElements.keyAt(i);
+            if (sharedElement != null && sharedElement.isAttachedToWindow() && name != null) {
+                mSharedElements.add(sharedElement);
+                mSharedElementNames.add(name);
+            }
+        }
         if (getViewsTransition() != null && mTransitioningViews != null) {
             ViewGroup decorView = getDecor();
             if (decorView != null) {