Skip to content

The SDK doesn't handle configuration changes correctly and causes a memory leak #835

@francescocervone

Description

@francescocervone

Checklist

Description

If the user performs a configuration change (e.g. rotate the device, change font or display size, change locale, enable / disable dark mode, ...) during the login flow, the Auth0 SDK doesn't deliver the login result correctly to the caller app.

Since the root cause of this issue is the same as #833, and since if you follow the steps below with the demo app on the main branch you get a crash (root cause explained below), you can reproduce this issue by using the demo app from the branch of this PR #832.

Basically, when a configuration change occurs, all the activities in the stack get recreated and the old instances thrown away.
So, the instance that started the login flow with the WebAuthProvider.login is destroyed. When the callback returns it notifies the destroyed activity.

Indeed this also actually leads to a memory leak, since the SDK is referencing a destroyed activity.

This is also the reason why the demo on the main branch is crashing, because the Fragment that was detached from its activity after it was destroyed is receiving the callback and calls the requireContext().

Suggested solution

Also in this case, like #833, the suggested solution is to use the Android's activity result API.

Reproduction

  1. Launch the demo app (on the same branch as Reproduce don't keep activities issue #832)
  2. Click on "LOG IN WITH BROWSER"
  3. Rotate the device
  4. Actually log in
  5. The snackbar doesn't appear

Additional context

No response

Auth0.Android version

3.7.0

Android version(s)

Any

Metadata

Metadata

Assignees

Labels

bugThis points to a verified bug in the code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions