# State Layer

The State layer provides observable state management for feeds and activities in Stream Feeds. It uses Kotlin `StateFlow` properties to automatically update your UI when data changes.

## FeedState

`FeedState` manages the state of a feed, including activities, followers, members, and pagination information. It automatically updates when the feed data changes.

### Getting FeedState

To access the state of a feed, you need to create a `Feed` instance and access its `state` property:

```kotlin label="Kotlin"
// Create a feed id
val fid = FeedId(group = "user", id = "john")

// Create the feed instance from your client
val feed = client.feed(fid = fid)

// Get the latest data
feed.getOrCreate()

// Access the state
val feedState = feed.state
```

### Available Properties

The `FeedState` provides the following properties:

```kotlin label="Kotlin"
// Core feed data
val feed: StateFlow<FeedData?>                                    // The feed information
val activities: StateFlow<List<ActivityData>>                     // Activities in the feed
val aggregatedActivities: StateFlow<List<AggregatedActivityData>> // Aggregated activities (for aggregated feeds)
val pinnedActivities: StateFlow<List<ActivityPinData>>            // Pinned activities

// Follow relationships
val followers: StateFlow<List<FollowData>>              // Users following this feed
val following: StateFlow<List<FollowData>>              // Feeds this user follows
val followRequests: StateFlow<List<FollowData>>         // Pending follow requests

// Feed members
val members: StateFlow<List<FeedMemberData>>            // Members of the feed

// Notification status
val notificationStatus: StateFlow<NotificationStatusResponse?> // Notification status (for notification feeds)

// Pagination
val canLoadMoreActivities: Boolean                      // Whether more activities can be loaded
```

## ActivityState

`ActivityState` manages the state of a single activity, including its comments, reactions, and associated poll data. It also updates automatically.

### Getting ActivityState

To access the state of an activity, you need to create an `Activity` instance:

```kotlin label="Kotlin"
// Create an activity instance
val activity = client.activity(
    activityId = "activity-123",
    fid = FeedId(group = "user", id = "john")
)

// Get the latest data
activity.get()

// Access the state
val activityState = activity.state
```

### Available Properties

The `ActivityState` provides the following properties:

```kotlin label="Kotlin"
val activity: StateFlow<ActivityData?>             // The activity data
val comments: StateFlow<List<ThreadedCommentData>> // Comments on the activity
val poll: StateFlow<PollData?>                     // Associated poll (if any)
```

---

For the most recent version of this documentation, visit [https://getstream.io/activity-feeds/docs/android/state/](https://getstream.io/activity-feeds/docs/android/state/).