---
title: Configure a notification listener using the Android SDK
slug: feature-experimentation/docs/set-up-notification-listener-android
docTags: 
createdAt: 2026-08-05T20:39:53.000Z
---

Notification listeners trigger a callback function that you define when certain actions are triggered in the SDK.

The most common use case is to send a stream of all feature flag decisions to an analytics provider or to an internal data warehouse to join it with other data that you have about your users.

## Notification listener types

For information about notification listener types and use cases, see [Notification listeners](docId:0d__cjuKECyJGqgTV0_5e).

For code samples, see the following sections.

:::hint{type="info"}
**Note**
The follow code examples assume you have already [initialized the Android SDK](docId\:yOiJjsSgQ1uieWHJkR42D) and have created an `optimizelyClient` instance.
:::

## Add and remove all notification listeners

The following example code shows how to add a listener, remove a listener, remove all listeners of a specific type (such as all decision listeners), and remove all listeners.

```kotlin
// Add Notification Listener (LogEvent)
val notificationId = optimizelyClient.addLogEventNotificationHandler { logEvent: LogEvent ->
    Log.d("Optimizely", "event dispatched: $logEvent")
}

// Remove Notification Listener
optimizelyClient.notificationCenter!!.removeNotificationListener(notificationId)

// Remove all Notification Listeners
optimizelyClient.notificationCenter!!.clearAllNotificationListeners()

// Remove all Notification Listeners of a certain type
optimizelyClient.notificationCenter!!.clearNotificationListeners(DecisionNotification::class.java)
```

```java
// Add Notification Listener (LogEvent)
int notificationId = optimizelyClient.addLogEventNotificationHandler(logEvent -> {
    Log.d("Optimizely", "event dispatched: " + logEvent);
});

// Remove Notification Listener
optimizelyClient.getNotificationCenter().removeNotificationListener(notificationId);

// Remove all Notification Listeners
optimizelyClient.getNotificationCenter().clearAllNotificationListeners();

// Remove all Notification Listeners of a certain type
optimizelyClient.getNotificationCenter().clearNotificationListeners(DecisionNotification.class);
```

## Configure each type of notification listener

The following example code shows how to configure each type of notification listener.

```kotlin
// SET UP DECISION NOTIFICATION LISTENER
val notificationId1 = optimizelyClient.addDecisionNotificationHandler { notification: DecisionNotification ->
    // Access type on decisionObject to get type of decision
    val decisionType = notification.type
    if (decisionType == "flag") {
       val flagDecisionInfo = notification.decisionInfo
       val flagKey = flagDecisionInfo["flagKey"] as? String
       val enabled = flagDecisionInfo["enabled"] as? Boolean
       val decisionEventDispatched = flagDecisionInfo["decisionEventDispatched"] as? Boolean
       // Send data to analytics provider here
    }
}

// SET UP LOG EVENT NOTIFICATION LISTENER
val notificationId2 = optimizelyClient.addLogEventNotificationHandler { notification: LogEvent ->
    // process the logEvent object here (send to analytics provider, audit/inspect data)
}

// SET UP OPTIMIZELY CONFIG NOTIFICATION LISTENER
// You will get notifications whenever the datafile is updated except for SDK initialization
val notificationId3 = optimizelyClient.addUpdateConfigNotificationHandler { notification: UpdateConfigNotification ->
    val optimizelyConfig = optimizelyClient.optimizelyConfig
}

// SET UP TRACK LISTENER
val notificationId4 = optimizelyClient.addTrackNotificationHandler { notification: TrackNotification ->
    // process the event here (send to analytics provider, audit/inspect data)
}
```

```java
// SET UP DECISION NOTIFICATION LISTENER
int notificationId1 = optimizelyClient.addDecisionNotificationHandler(notification -> {
    // Access type on decisionObject to get type of decision
    String decisionType = notification.getType();
    if ("flag".equals(decisionType)) {
       Map<String, ?> flagDecisionInfo = notification.getDecisionInfo();
       String flagKey = (String) flagDecisionInfo.get("flagKey");
       Boolean enabled = (Boolean) flagDecisionInfo.get("enabled");
       Boolean decisionEventDispatched = (Boolean) flagDecisionInfo.get("decisionEventDispatched");
       // Send data to analytics provider here
    }
});

// SET UP LOG EVENT NOTIFICATION LISTENER
int notificationId2 = optimizelyClient.addLogEventNotificationHandler(notification -> {
    // process the logEvent object here (send to analytics provider, audit/inspect data)
});

// SET UP OPTIMIZELY CONFIG NOTIFICATION LISTENER
// You will get notifications whenever the datafile is updated except for SDK initialization
int notificationId3 = optimizelyClient.addUpdateConfigNotificationHandler(notification -> {
    OptimizelyConfig optimizelyConfig = optimizelyClient.getOptimizelyConfig();
});

// SET UP TRACK LISTENER
int notificationId4 = optimizelyClient.addTrackNotificationHandler(notification -> {
    // process the event here (send to analytics provider, audit/inspect data)
});
```
