8

I am adding content transitions to a pretty large app and in most cases I do not have any shared elements but still want to use the transition animations. I have tracked the problem down to this line of code:

ActivityOptionsCompat.makeSceneTransitionAnimation(activity, ????);

I have tried setting Pair array to null or an empty array and I have tried just leaving it out. Everything results in the following error:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewRootImpl.setPausedForTransition(boolean)' on a null object reference

However, I only get this error on Android 6.0+, it works fine on any version of Android 5. Am I trying to do this the wrong way?

Corgrimm
  • 153
  • 6
  • Did you found a solution for this issue? – Eitan Jun 15 '16 at 10:28
  • Not a real answer hence the comment. The exception doesn't seem to break anything important, so catching the exception makes the animation work just fine – Olumide Sep 13 '16 at 09:40

3 Answers3

2

I did a bunch of digging in the source code and it looks like this is caused by a missed null pointer check that got fixed for Nougat.

I've got no clue how to work around it on 6.x though, unfortunately. I suppose you could add a 6.x try/catch if it's really killing you in terms of crashes, but that may also catch a bunch of other stuff you may not want it to.

DesignatedNerd
  • 2,514
  • 1
  • 23
  • 46
0

It's not an exact answer, rather a workaround; but I have managed to resolve this by postponing animations using handler.postDelayed(...) and Runnable.

You can check out the code of my solution in this question.

To be honest, it's still a lil bit too hacky for me and that's why I'm still waiting for answers with more elegant solutions. Moreover, I suppose that it only makes sense in cases similar to mine, when transitions are invoked right after creating the view.

mkoslacz
  • 121
  • 2
  • 8
0

I faced a similar problem. The issue was that I was setting

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK) 

Which killed the activity from which I was launching the transition. Removing that fixed the issue for me on Android M.

Grr
  • 15,553
  • 7
  • 65
  • 85
Rakesh Gopathi
  • 302
  • 1
  • 12