Fix: Handle configuration changes correctly to prevent memory leak#846
Conversation
| ctOptions = options | ||
| return this | ||
| } | ||
|
|
There was a problem hiding this comment.
Please don't remove the extra lines between methods
| } | ||
|
|
||
| internal fun onRestoreInstanceState(bundle: Bundle) { | ||
| if (managerInstance == null) { |
There was a problem hiding this comment.
Isn't this check required now?
|
Code formatting has been distorted. Please fix them |
|
Hi. How does this change fix the issue? If the listener passed to the So, when the result comes from the browser, it is dispatched to the destroyed Activity. Could you please explain how this works? Thanks! |
|
Hi @francescocervone , This PR was created with the intention of being a temporary fix for the memory leak issue while we migrate to the recommended approach in the next major release, but as you mentioned we won't be able to handle all the scenarios with this method . We will be closing this |
Description
This PR fixes bug where a configuration change (e.g., device rotation) during the web authentication flow would cause a memory leak and crash the application.
The WebAuthProvider was holding a direct reference to the callback from the Activity or Fragment that started the login. When the device was rotated, the original Activity/Fragment was destroyed, but the SDK still held onto the stale reference. When the login result returned, it was sent to this destroyed context, causing an IllegalStateException and preventing the new, active UI from receiving the result.
Changes
The WebAuthProvider.java now maintains a static list of active callbacks. This list survives configuration changes, ensuring it can always deliver a pending result to a valid listener.
The DatabaseLoginFragment is updated to correctly manage its lifecycle. It registers itself as a listener in onStart() by calling WebAuthProvider.addCallback(this) and unregisters in onStop() with WebAuthProvider.removeCallback(this).
References
#835
Testing
All existing Unit tests are passed
Checklist
I have read the Auth0 general contribution guidelines
I have read the Auth0 Code of Conduct
All existing and new tests complete without errors