fix activity leak after configuration change
ISSUE SOLVED: 112
Problem
During the configuration change process, the onDispose method in AndroidScreenLifecycleOwner is not called. As I understand it, this is normal, because almost all DisposableEffects in voyager ignore configuration changes.
But this leads to the fact that atomicContext.getAndSet(null) in onDispose is not executed and the activity leaks.
The side effect of such a leak is that when the onDispose method in AndroidScreenLifecycleOwner is called, it will not work correctly, because this code
if (activity != null && activity.isChangingConfigurations) return
will complete the function execution because reference here for the old activity in which isChangingConfigurations is true
Solution
I simply add a callback to the lifecycle that resets the atomicContext field when activity is in onDestory state.
If
onDisposeis not called when the configuration changes (or am i wrong?), maybe we can get rid ofactivity.isChangingConfigurationscheck, then get rid of the reference to the activity context and store a reference to the application context instead?
I was dive into the code this days and I also though about this.