PainlessMusicPlayer
PainlessMusicPlayer copied to clipboard
Crash on shared element transition
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:
-
Dispose Cursor
onDestroy
. Drawbacks: we will have opened cursors while in background, which is not that good. -
Make View snapshot for transition. Drawbacks: high complexity and more code.