Skip to content

Conversation

@tylerjroach
Copy link

Summary

Delays the feature flag loadFlags() network request from SDK initialization to when the app first enters the foreground. This prevents a large number of devices from waking up at the same time (push notification) and requesting flags at the same time. Flags should only be loaded automatically when a user opens the app to the foreground.

Problem

When customers initialize the Mixpanel SDK in their Application.onCreate(), the loadFlags() network call was triggered immediately during MixpanelAPI.getInstance().

  1. Wake up in the background to handle the push
  2. Run through Application.onCreate()
  3. Initialize MixpanelAPI
  4. Immediately hit the feature flags endpoint

Solution

  • Moved loadFlags() call from the MixpanelAPI constructor to onForeground()
  • Added two AtomicBoolean flags to control behavior:
    • mHasAppForegrounded: Tracks whether the app has ever entered foreground
    • mInitialFeatureFlagLoad: Ensures the initial load only happens once

@tylerjroach tylerjroach changed the title Delay Feature Flag networking call until the app has been foregrounded. fix: Delay Feature Flag networking call until the app has been foregrounded. Dec 9, 2025
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.

2 participants