Skip to content

Conversation

@tylerjroach
Copy link
Contributor

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
Copy link
Collaborator

@jaredmixpanel jaredmixpanel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tylerjroach tylerjroach merged commit a55681b into master Jan 7, 2026
5 checks passed
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.

3 participants