PainlessMusicPlayer icon indicating copy to clipboard operation
PainlessMusicPlayer copied to clipboard

Crash on shared element transition

Open Doctoror opened this issue 6 years ago • 0 comments

The problem: Cursors in CursorRecyclerAdapter are cleared onStop, sometimes causing crash in shared element transitions because the views no longer attached to the adapter after onStop.

Steps to reproduce:

  • go to tracks search
  • perform search
  • click on found item

Expected results: shared element transition to NowPlayingActivity

Observed results:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.transformMatrixToGlobal(android.graphics.Matrix)' on a null object reference
    at android.view.GhostView.calculateMatrix(GhostView.java:89)
    at android.app.ActivityTransitionCoordinator$GhostViewListeners.onPreDraw(ActivityTransitionCoordinator.java:967)
    at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)

All proposed solutions have drawbacks:

  1. Dispose Cursor onDestroy. Drawbacks: we will have opened cursors while in background, which is not that good.

  2. Make View snapshot for transition. Drawbacks: high complexity and more code.

Doctoror avatar May 06 '18 08:05 Doctoror