amplitude / Amplitude-Kotlin

Amplitude Kotlin SDK
MIT License
28 stars 11 forks source link

Android SDK is making background requests when the app is closed observed up to 9 minutes #104

Open rubixhacker opened 1 year ago

rubixhacker commented 1 year ago

Expected Behavior

After the initial flush on close, the Amplitude SDK should not make additional background requests.

Current Behavior

Background network requests are made every 30 seconds, depending on the device, for one minute to nine minutes. Even with flushEventsOnClose set as false and flushMaxRetries set as zero.

Possible Solution

The issue appears to lie in amplitudeScope, AndroidLifecyclePlugin should cancel all children scopes and then restart all the children scopes when the app returns to the foreground

Steps to Reproduce

  1. Implement the Amplitude SDK in an Android app
  2. With the app running open the App Inspection tab in Android Studio
  3. Go to the Network Inspector tab
  4. Background the app (close or hit the home button)
  5. Notice that network calls are made every 30 seconds to https://api2.amplitude.com/2/httpapi

Environment

qingzhuozhen commented 1 year ago

Thanks for reporting this! This is potentially for background requests and retries. We would dive more into this behavior.

rubixhacker commented 1 year ago

Hi @qingzhuozhen,

Were you able to investigate this issue further? This past weekend we had a user report that our app used over 45GB of data in the background, and the only thing we can identify as using the data is the Amplitude SDK. We have been instructing users facing this issue to restrict background access of the app, and that stops the background requests from the Amplitude SDK.

qingzhuozhen commented 1 year ago

Hi @rubixhacker, the 30s interval is already updated in the newer versions, so if you upgrade the SDK version this should be resolved. I am also adding more enforcement on retries to prevent it.