Skip to content

Background polling not working for large polling intervals? #124

@carloswabreu1

Description

@carloswabreu1

Describe the bug
According to your documentation:

When the app is backgrounded, the stream connection terminates. The SDK polls for flag updates every hour (or another interval you configure) to stay in sync

I could confirm that the SDK works as expected in the foreground and that background polling is working as expected for both 15min and 1 hour intervals when the app is in the background. However, for large polling intervals (I've tried 12 and 24h), the flag is not being updated. I've included my testing implementation bellow. Can you please confirm this is an issue? Am I doing something wrong?

To reproduce

  1. Setup LaunchDarkly client in the Application onCreate method with a large polling interval, e.g. 12h
  2. Open the app, confirm that changing the flag remotely immediately reflects a flag change locally
  3. Exit the app. Change the flag remotely one last time
  4. Wait for 24h without opening the app. The flag is never updated locally. Usually the system kills the process during this period but the flag is not updated even when the process is brought to life in the background
  5. Open the app, the flag is immediately updated

Expected behavior
The flag should be updated in the background for long polling periods on or around the background polling period defined

Logs
I have none but I'm happy to provide upon request

SDK version
implementation 'com.launchdarkly:launchdarkly-android-client-sdk:2.14.1'

OS/platform
Tested on a Pixel 3a, Android 11

Additional context
Bellow is the current implementation (Application class). You may notice that we have defined a secondary key as we wish to have flags synced from two different projects.

@Override
public void onCreate() {
        (...)
        Map<String, String> otherKeys = new HashMap<String, String>();
        otherKeys.put("secondaryIdentifier", "secondaryKey");

        LDConfig ldConfig = new LDConfig.Builder()
                .setMobileKey("mainKey")
                .setSecondaryMobileKeys(otherKeys)
                .setBackgroundPollingIntervalMillis(12 * 60 * 60 * 1000)
                .build();

        LDUser user = new LDUser.Builder("user")
                .build();

        LDClient appClient = LDClient.init(this, ldConfig, user, 0);
        appClient.registerAllFlagsListener(new LDAllFlagsListener() {
            @Override
            public void onChange(List<String> flagKey) {
                for (String flag : flagKey) {
                    //Persisting flag to disk
                }
            }
        });

        //Sdk-related setup
        try {

            LDClient ldSdkClient = LDClient.getForMobileKey("secondaryIdentifier");
            ldSdkClient.registerAllFlagsListener(new LDAllFlagsListener() {
                @Override
                public void onChange(List<String> flagKey) {
                    for (String flag : flagKey) {
                        //Persisting flag to disk
                    }
                }
            });
        } catch (LaunchDarklyException e) {
            e.printStackTrace();
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions