使用SharedElement在活动转换中崩溃

时间:2015-12-10 13:52:58

标签: android android-5.0-lollipop shared-element-transition activity-transition

我正在使用来自ViewPager(在调用活动中)的Activity转换以及共享元素和内容转换。重新进入调用活动时,我遇到了这个崩溃:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.ResultReceiver.send(int, android.os.Bundle)' on a null object reference
  at android.app.EnterTransitionCoordinator.sendSharedElementDestination(EnterTransitionCoordinator.java:199)
  at android.app.EnterTransitionCoordinator.viewsReady(EnterTransitionCoordinator.java:123)
  at android.app.EnterTransitionCoordinator$2.onPreDraw(EnterTransitionCoordinator.java:148)
  at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:895)
  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2153)
  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1180)
  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6558)
  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
  at android.view.Choreographer.doCallbacks(Choreographer.java:590)
  at android.view.Choreographer.doFrame(Choreographer.java:560)
  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:145)
  at android.app.ActivityThread.main(ActivityThread.java:5832)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)

此外,一旦返回,屏幕开始闪烁,白屏闪烁。

以下是我的过渡标志:

<item name="android:windowContentTransitions">true</item>
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowAllowReturnTransitionOverlap">false</item>

我尝试在Calling和Called活动中设置Enter / Exit转换,但没有运气。

1 个答案:

答案 0 :(得分:0)

尝试从FragmentManager获取片段:

fragmentManager.findFragmentByTag("android:switcher:" + R.id.viewPager + ":" + position)

如果fragment为null,请尝试创建一个新的fragment。