Flushing Events Periodically
Detailed steps to flush events periodically from the RudderStack SDK’s internal database to Rudder Server.
RudderStack supports periodic flushing of events from the Android SDK to RudderStack, irrespective of whether your app is opened or not. This ensures that the events that are triggered just before closing the app are sent from the device - even if the app is not opened by the user for a long time.
To use this feature, follow these steps:
Open your
app/build.gradle
and add the WorkManager dependency underdependencies
as shown below:
Use
withFlushPeriodically()
function while passing theRudderConfig
object to thegetInstance()
API, as shown below:
withFlushPeriodically
parameters
withFlushPeriodically
parametersThe withFlushPeriodically
function takes two parameters:
The first parameter is the number representing the time interval for the flushing to be repeated.
The second parameter is the time unit of the repeat interval. It can be Minutes, Hours, or Days. The minimum value of the repeat interval is 15 minutes.
Initializing WorkManager on demand
By default, the WorkManager is initialized on the startup of the application. However, you can initialize it only on demand by following the below steps:
Add the below
provider
to the application tag of your application’sAndroidManifest.xml
.
Implement
Configuration.Provider
and define the functiongetWorkManagerConfiguration()
in your application class as shown below:
Contact us
For queries on any of the sections covered in this guide, you can contact us or start a conversation in our Slack community.
Last updated
Was this helpful?