KeyManager::decrementAndMaybeRemoveKey crashes in case if traversal completion was performed after Activity destroy
I observed this crash when I was working on screen transition animation logic setup on top of the Flow. After enabling Don't keep activities developer option in device settings, I tried to minimize application during transition animation and crash has occurred.
In my case I placed TraversalCallback::onTraversalCompleted method call inside of transition animation completion callback. This callback was fired after activity was destroyed and because of that node instance inside of KeyManager::decrementAndMaybeRemoveKey was null. So I received NPE when library was trying to access ManagedServices::uses field on a null value object instance.
The easiest fix that I've found for this issue is just to add null check for node variable inside of KeyManager::decrementAndMaybeRemoveKey method body: if(node == null) { return false; }.
Please let me know if I'm missing something here or if some other solution should be applied to fix this issue. I will appreciate for your help.
This seems like an animation/lifecycle bug in the app. I think the animation should probably have been canceled when the activity paused, and your animation handler should have immediately completed the traversal.
I'm hesitant to add a null check because that could hide bugs (including this?).