launchdarkly / android-client-sdk

LaunchDarkly Client-side SDK for Android
Other
45 stars 23 forks source link

Backgrounding and Foregrounding app triggers onFeatureFlagChange() #119

Closed dsuresh-ap closed 3 years ago

dsuresh-ap commented 3 years ago

Describe the bug Backgrounding and foregrounding the app triggers onFeatureFlagChange for every listener. Is this intended since no flags actually changed. The flag update type when debugging shows as FlagStoreUpdateType.FLAG_CREATED.

To reproduce

  1. Add a listener to the client using .registerFeatureFlagListener.
  2. Background the app
  3. Foreground the app

Expected behavior No flags actually changed so onFeatureFlagChange should not trigger.

Logs N/A

SDK version 2.12.0

Language version, developer tools Android Studio 4.1.2

OS/platform macOS 11.2.1

Additional context I see that the method being called is public void clearAndApplyFlagUpdates(List<? extends FlagUpdate> flagUpdates) which makes me feel like this is intentional.

gwhelanLD commented 3 years ago

Hi @dsuresh-ap,

clearAndApplyFlagUpdates is supposed to override all flags (it's used when receiving a complete set of flags from the service, so we ignore any flag versions and trust that it's a consistent state) but we're planning on updating the SDK to track changes against the previously cached flags rather than the empty store post-clear. Thanks for reporting this, as it does effect the usefulness of the flag change listeners, I'll leave the issue open until we get change out that handle the flag change tracking when the cached flags are replaced.

Thanks, @gwhelanLD

gwhelanLD commented 3 years ago

Hi @dsuresh-ap,

The 3.0.0 release should address this issue. The SDK will now properly compare the new values received to the cached values even when receiving an entire flag value set from the LaunchDarkly service.

Thanks, @gwhelanLD