Fix: Handle configuration changes correctly to prevent memory leak #846
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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