Custom

If for some reason, you need to implement your own dispatcher, you must create a BatchEventDispatcher and register it to the SDK using Batch.EventDispatcher.addDispatcher(BatchEventDispatcher).

You don't need to add a dispatcher if you're using one of the previous "ready-to-go" library ! It will be automatically registered.

class MyKotlinApplication : Application(), BatchEventDispatcher {

    override fun onCreate() {
        super.onCreate()

        Batch.start("MY_API_KEY")
        registerActivityLifecycleCallbacks(BatchActivityLifecycleHelper())

        // [...]

        Batch.EventDispatcher.addDispatcher(this)
    }

    override fun dispatchEvent(type: Batch.EventDispatcher.Type,
                               payload: Batch.EventDispatcher.Payload) {
        Log.d("Dispatcher", "I'm dispatching : " + type.name)
    }
}

If the Batch SDK happens to be opt-out (from the user or because the SDK is opt-out by default), dispatchers won't receive any events.

Last updated

Was this helpful?