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

Commits on Nov 17, 2021

  1. Fix UnsupportedOperationException if a leaked Activity.recreate is ca…

    …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 committed Nov 17, 2021
    Copy the full SHA
    6fdc8ef View commit details
    Browse the repository at this point in the history