---
title: Real-Time Audiences for Feature Experimentation segment qualification methods for the Android SDK
slug: feature-experimentation/docs/real-time-audiences-for-feature-experimentation-segment-qualification-methods-android
docTags: 
createdAt: 2026-08-05T20:39:53.000Z
---

## Prerequisites

You must enable the [Real-Time Audiences for Feature Experimentation integration](docId:6UBBxxRv331nBIVZ2lun8) before fetching qualified audiences and checking if the user is qualified for the given audience.

## fetchQualifiedSegments

### Minimum SDK version

4.0.0

### Description

You can use the `fetchQualifiedSegments` method to retrieve the external audience mapping for a specific user from the ODP server. The Optimizely Feature Experimentation Android SDK provides a synchronous and asynchronous version of the `fetchQualifiedSegments` method. The qualified segments are cached.

- The synchronous fetch blocks the caller until it completes.
- The asynchronous API does not block the caller.

`fetchQualifiedSegments` is a method of the `UserContext` object. See [OptimizelyUserContext](docId\:SPUvctrnEAYbsSJQuwWX9) for details.

### Parameters

The following table describes the parameters for the `fetchQualifiedSegments` method:

| Parameter                             | Type                     | Description                                              |
| ------------------------------------- | ------------------------ | -------------------------------------------------------- |
| `options` (optional)                  | `List<ODPSegmentOption>` | A set of options for fetching qualified segments.        |
| `completion` (for asynchronous calls) | Callback function        | A completion handler to be called with the fetch result. |

### Returns – Synchronous call

The `fetchQualifiedSegments` synchronous method returns `true` if the qualified segments array in the [user context](docId\:SPUvctrnEAYbsSJQuwWX9) was updated.

### Returns – Asynchronous call

- If the fetch completes, the Android SDK will update the qualified segments array in the  [OptimizelyUserContext](docId\:SPUvctrnEAYbsSJQuwWX9) and then call the completion handler with a success status.
- If the fetch fails, the SDK will call the handler with a failure status.

:::hint{type="info"}
**Note**
You can read and write directly to the qualified segments array. This lets you bypass the remote fetching process from Optimizely Data Platform (ODP) or use your own fetching service. This can be helpful when testing or debugging.
:::

### Example fetchQualifiedSegments

The following is an example of calling the `fetchQualifiedSegments` method and accessing the returned completion object.

### Kotlin example

```kotlin
val attributes: MutableMap<String, Any> = HashMap() 
       attributes.put("app_version", "1.3.2") 
       val user = optimizelyClient.createUserContext("fs-id-123", attributes) 
 
// Without segment option 
       user!!.fetchQualifiedSegments { isFetchSuccessful: Boolean? -> 
           println(isFetchSuccessful) 
           val decision = user.decide("flag1") 
           user.trackEvent("purchase_event") 
       } 
 
// With segment options 
       val odpSegmentOptions: MutableList<ODPSegmentOption> = ArrayList() 
       odpSegmentOptions.add(ODPSegmentOption.IGNORE_CACHE) 
       odpSegmentOptions.add(ODPSegmentOption.RESET_CACHE) 
       user.fetchQualifiedSegments( 
           { isFetchSuccessful: Boolean? -> 
               println(isFetchSuccessful) 
               val decision = user.decide("flag1") 
               user.trackEvent("purchase_event") 
           }, 
           odpSegmentOptions 
       ) 
```

```kotlin
val attributes: MutableMap<String, Any> = HashMap() 
       attributes.put("app_version", "1.3.2") 
 
// Method 1 create with user id 
       val userWithUserId = optimizelyClient.createUserContext("fs-id-123", attributes) 
 
// Without segment option 
       val response = userWithUserId!!.fetchQualifiedSegments() 

// With segment options 
       val odpSegmentOptions: MutableList<ODPSegmentOption> = ArrayList() 
       odpSegmentOptions.add(ODPSegmentOption.IGNORE_CACHE) 
       odpSegmentOptions.add(ODPSegmentOption.RESET_CACHE) 

       val responseWithOptions = userWithUserId!!.fetchQualifiedSegments(odpSegmentOptions) 
 
       val decision = userWithUserId!!.decide("flag1") 
       userWithUserId!!.trackEvent("myevent") 
 
// Method 2 create OptimizelyUserContext with auto-generated VUID instead of user id 
       val userWithVuid = optimizelyClient.createUserContext(attributes) 
 
// Without segment option 
       val vuidResponse = userWithVuid!!.fetchQualifiedSegments() 
 
// With segment option 
val vuidSegmentOptions: MutableList<ODPSegmentOption> = ArrayList() 
vuidSegmentOptions.add(ODPSegmentOption.IGNORE_CACHE) 
vuidSegmentOptions.add(ODPSegmentOption.RESET_CACHE) 
 
val vuidResponseWithOptions = userWithVuid!!.fetchQualifiedSegments(vuidSegmentOptions) 
 
val vuidDecision = userWithVuid!!.decide("flag1") 
userWithVuid!!.trackEvent("myevent") 
```

### Android example

```java
Map<String, Object> attributes = new HashMap<>();
attributes.put("app_version", "1.3.2");
OptimizelyUserContext user = optimizelyClient.createUserContext("fs-id-123", attributes);

// Without segment option 
user.fetchQualifiedSegments((Boolean isFetchSuccessful) -> {
            System.out.println(isFetchSuccessful);
            
            OptimizelyDecision decision = user.decide("flag1");
            user.trackEvent("purchase_event");
        });

// With segment options
List<ODPSegmentOption> odpSegmentOptions = new ArrayList<>();
odpSegmentOptions.add(ODPSegmentOption.IGNORE_CACHE);
odpSegmentOptions.add(ODPSegmentOption.RESET_CACHE);

user.fetchQualifiedSegments((Boolean isFetchSuccessful) -> {
            System.out.println(isFetchSuccessful);
            
            OptimizelyDecision decision = user.decide("flag1");
            user.trackEvent("purchase_event");
        },
        odpSegmentOptions);
```

```java
Map<String, Object> attributes = new HashMap<>();
attributes.put("app_version", "1.3.2");

// Method 1 create with user id
OptimizelyUserContext userWithUserId = optimizelyClient.createUserContext("fs-id-123", attributes);

// Without segment option 
Boolean response = userWithUserId.fetchQualifiedSegments();

// With segment options
List<ODPSegmentOption> odpSegmentOptions = new ArrayList<>();
odpSegmentOptions.add(ODPSegmentOption.IGNORE_CACHE);
odpSegmentOptions.add(ODPSegmentOption.RESET_CACHE);

Boolean responseWithOptions = userWithUserId.fetchQualifiedSegments(odpSegmentOptions);


OptimizelyDecision decision = userWithUserId.decide("flag1");
userWithUserId.trackEvent("myevent");


// Method 2 create OptimizelyUserContext with auto-generated VUID instead of user id
OptimizelyUserContext userWithVuid = optimizelyClient.createUserContext(attributes);

// Without segment option 
Boolean vuidResponse = userWithVuid.fetchQualifiedSegments();


// With segment options
List<ODPSegmentOption> vuidSegmentOptions = new ArrayList<>();
vuidSegmentOptions.add(ODPSegmentOption.IGNORE_CACHE);
vuidSegmentOptions.add(ODPSegmentOption.RESET_CACHE);

Boolean vuidResponseWithOptions = userWithVuid.fetchQualifiedSegments(vuidSegmentOptions);


OptimizelyDecision vuidDecision = userWithVuid.decide("flag1");
userWithVuid.trackEvent("myevent");
```

The following diagram shows the network calls between your application, the Feature Experimentation Android SDK, and ODP when calling `fetchQualifiedSegments`:

![](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/I1RnqFr_ctDAjL_lA3nGM_f4695fde09f10c029530cc71f5504e6779ba7cc0ab97fe3633fd2fb39ae2f9b1-rts-network-diagrams-android-fetchqualifedsegments.png)

1. Your application calls the `fetchQualifiedSegments` method.
2. The Feature Experimentation Android SDK makes a GraphQL call to ODP to fetch audience segments the user ID qualifies for.
3. ODP responds with the qualified audience segments.
4. The Android SDK automatically caches the fetched segments mapping the user ID to the qualified segments. See the [OdpSegmentManager](docId:6bwQvgh0y3J5hTw_SIQJ2) section.
5. The `fetchQualifiedSegments` method returns a boolean if the qualified segments array was updated.
6. Call the `decide` method to get the flag decision for a given user, a decision object that contains the flag's status (enabled or disabled), and the assigned variation key.

### OdpSegmentManager

When the segments are fetched, they are cached. This means that if you request the segments again (when new user contexts are created), the audience segment information can be retrieved from the cache instead of being fetched from the remote ODP server.

The cache is used for the `fetchQualifiedSegment` call. This method is called on the user context (the user context is fixed, including the real-time audiences the user qualifies for).

The cache *only* applies when calling the `fetchQualifiedSegments` call. If you set the cache size to `0`, the SDK disables the cache. A cache timeout of `0` means cached entries never expire. Optimizely uses a Least Recently Used (LRU) algorithm, so the oldest record is bumped out when the maximum size is reached. If there is a cache miss upon the method call, Optimizely makes a network request.

The Android SDK has an `OdpSegmentManager` module, which manages a segments cache that is shared for all user contexts. The cache is in memory (not persistent), so it is reset when the application is terminated or the device is rebooted.

Specifics about the cache include the following:

- Stores a mapping of user IDs to segments.
- The Android SDK calls the ODP server on cache miss or expiration.
- Uses LRU.
- Expires on timeout.
- Both cache size and timeout are configurable (default values provided).
- Is enabled by default and can be disabled.

If you want to bypass caching, you can add the following options to your `odpSegmentOptions` array:

- **ignoreCache** – Bypass segments cache for lookup and save.
- **resetCache** – Reset all segments cache.

See the [Kotlin](docId:6bwQvgh0y3J5hTw_SIQJ2) and [Android](docId:6bwQvgh0y3J5hTw_SIQJ2) code samples to see how to call `fetchQualifiedSegments` with caching options.

## isQualifiedFor

### Minimum SDK Version

4.0.0

### Description

Check if the user is qualified for the given audience segment.

### Parameters

The following table describes the parameters for the `isQualifiedFor` method:

| Parameter | Type   | Description                                                      |
| --------- | ------ | ---------------------------------------------------------------- |
| segment   | String | The audience segment name to check if the user is qualified for. |

### Returns

`true` if the user is qualified.

### Examples

The following is an example of whether the user is qualified for a segment:

```kotlin
val attributes: MutableMap<String, Any> = HashMap() 
attributes.put("mobile_os", "ios") 
val user: OptimizelyUserContext = optimizely.createUserContext("user123", attributes) 
 
val response = user.fetchQualifiedSegments() 
val isQualified = user.isQualifiedFor("segment1") 
```

```java
Map<String, Object> attributes = new HashMap<>();
attributes.put("mobile_os", "ios");
OptimizelyUserContext user = optimizely.createUserContext("user123", attributes);

Boolean response = user.fetchQualifiedSegments();
Boolean isQualified = user.isQualifiedFor("segment1");
```

## Source files

The language and platform source files containing the implementation for Android are available on [GitHub](https://github.com/optimizely/android-sdk/tree/master/odp/src/main/java/com/optimizely/ab/android/odp).
