Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UnsupportedOperationException if a leaked Activity.recreate is called #6862

Merged
merged 1 commit into from Nov 17, 2021

Conversation

copybara-service[bot]
Copy link

Fix UnsupportedOperationException if a leaked Activity.recreate is called

Previously, ActivityController.recreate determined the current state of the
underlying Activity by calling the global

ActivityLifecycleMonitorRegistry.getLifecycleStageOf

This method is unreliable for leaked Activities as a new
ActivityLifecycleMonitor is created before each test. This means that, for a
leaked Activity, the ActivityLifecycleMonitor from the previous test has
knowledge if its lifecycle state, not the new one. When the Activity state was
queried using the current ActivityLifecycleMonitor, an
UnsupportedOperationException occurred.

To fix this, avoid using ActivityLifecycleMonitor as the source of truth for
Activity State in ActivityController, and instead add a new member variable to
ActivityController that maintains the state. Having ActivityController rely on
ActivityLifecycleMonitor for Activity state is circuitous -- AndroidX Test is
already using ActivityController to drive Activity lifecycles, so the
source-of-truth state should exist inside of ActivityController itself.

…lled

Previously, ActivityController.recreate determined the current state of the
underlying Activity by calling the global

  ActivityLifecycleMonitorRegistry.getLifecycleStageOf

This method is unreliable for leaked Activities as a new
ActivityLifecycleMonitor is created before each test. This means that, for a
leaked Activity, the ActivityLifecycleMonitor from the previous test has
knowledge if its lifecycle state, not the new one.  When the Activity state was
queried using the current ActivityLifecycleMonitor, an
UnsupportedOperationException occurred.

To fix this, avoid using ActivityLifecycleMonitor as the source of truth for
Activity State in ActivityController, and instead add a new member variable to
ActivityController that maintains the state. Having ActivityController rely on
ActivityLifecycleMonitor for Activity state is circuitous -- AndroidX Test is
already using ActivityController to drive Activity lifecycles, so the
source-of-truth state should exist inside of ActivityController itself.

PiperOrigin-RevId: 410168815
@hoisie hoisie merged commit 662a2fe into master Nov 17, 2021
@hoisie hoisie deleted the piper_410168815 branch November 17, 2021 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant