New Features in Android (Kotlin) SDK

Learn about the new and improved features in Android (Kotlin) SDK compared to the Android (Java) SDK.

This section highlights the new and improved features in the Android (Kotlin) SDK compared to the Android (Java) SDK.

New features

The Android (Kotlin) SDK introduces several features not available in the Android (Java) SDK.

Modern Kotlin concurrency

The Android (Kotlin) SDK leverages Kotlin coroutines and structured concurrency for non-blocking, main-thread-safe operations. Reactive state management ensures predictable state updates and thread-safe data access.

Custom plugins

Custom plugins let you intercept and transform events at any point in the analytics pipeline. With this feature, you can:

  • Enrich events with device context
  • Filter out sensitive data or drop specific information (for example, Application Opened and Application Backgrounded events) before it leaves the device.

The new plugin system lets you add, remove, or modify custom plugins at runtime.

// Create custom plugins
class CustomEventFilter : Plugin {
    override val pluginType: Plugin.PluginType = Plugin.PluginType.OnProcess

    override suspend fun intercept(event: Event): Event? {
        // Custom filtering logic
        return event
    }
}

analytics.add(CustomEventFilter())

See the Custom plugins guide for more information.

Multiple analytics instances

You can create and manage multiple analytics instances with different configurations.

Each instance maintains its own independent state, storage, and configuration — this is particularly useful for multi-tenant applications or tracking different data streams.

See the Multiple Instance Support guide for more information.

Custom logger

Allows custom logger implementations so you can route SDK logs to crash reporters, remote services, or your app’s existing logging system.

See the Logging APIs in Mobile SDKs guide for more information.

Custom plugins in integrations

You can add custom plugins to any supported integration to enhance event handling and processing.

Click here for an example that shows how to create a custom plugin for a destination. You can use it as a template for your own custom plugins.

The following example highlights a sample plugin that transforms (normalizes) track event names before they are sent to the Braze destination.

1. Create a custom plugin

import com.rudderstack.sdk.kotlin.core.Analytics
import com.rudderstack.sdk.kotlin.core.internals.logger.LoggerAnalytics
import com.rudderstack.sdk.kotlin.core.internals.models.Event
import com.rudderstack.sdk.kotlin.core.internals.models.TrackEvent
import com.rudderstack.sdk.kotlin.core.internals.plugins.Plugin

class EventNameNormalizationPlugin : Plugin {
    override val pluginType: Plugin.PluginType = Plugin.PluginType.OnProcess
    override lateinit var analytics: Analytics

    override fun setup(analytics: Analytics) {
        super.setup(analytics)
        this.analytics = analytics
    }

    /**
     * Intercepts analytics events and normalizes track event names by replacing spaces with underscores.
     *
     * @param event The event to modify
     * @return The modified event with normalized event name
     */
    override suspend fun intercept(event: Event): Event? {
        // Only process track events
        if (event !is TrackEvent) {
            return event
        }

        val originalEventName = event.event
        val normalizedEventName = originalEventName
            .trim()
            .replace(" ", "_")

        event.event = normalizedEventName

        LoggerAnalytics.verbose(
            "EventNameNormalizationPlugin: Transformed event name from \"$originalEventName\" to \"$normalizedEventName\""
        )

        return event
    }
}

2. Usage

  1. Create and add the Braze integration to the SDK:
val brazeIntegration = BrazeIntegration()
analytics.add(plugin = brazeIntegration)
  1. Add the custom plugin to the Braze integration:
brazeIntegration.add(plugin = EventNameNormalizationPlugin())
  1. Track events:
analytics.track("Product Added")
// The event will be transformed to: "Product_Added"

analytics.track("Checkout Started")
// The event will be transformed to: "Checkout_Started"

Behavior

Note that the above custom plugin:

  • Only modifies track events. It does not modify other event types (identify, screen, etc.).
  • Replaces all spaces with underscores in event names.
  • Logs transformations for debugging purposes.

Automatic screen tracking with NavController

The Android (Kotlin) SDK now supports automatic screen tracking for Jetpack Navigation. The legacy Android (Java) SDK had no built-in support for this — you had to manually call screen API for each navigation destination.

See the Automatic Screen Tracking guide for more information.

Shutdown API

You can explicitly shut down the analytics instance to terminate all ongoing operations. The SDK automatically removes all registered plugins and releases allocated resources. All events recorded before shutdown are persisted and processed on the next startup.

analytics.shutdown()

See the Shutdown API guide for more information.


Questions? Contact us by Email or on Slack