> ## Documentation Index
> Fetch the complete documentation index at: https://social-b97141fb-feat-user-history-moderation-detail.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Android Live Objects & Collections

> Observe social.plus Android SDK objects and collections with RxJava Flowable, Android Paging, and coroutine flows.

The Android SDK exposes live objects and collections through RxJava 3 streams. Singular reads such as `getPost(postId)` return `Flowable<T>`. Paged list queries return `Flowable<PagingData<T>>`. Some finite list queries return `Flowable<List<T>>`.

Use RxJava directly, or convert supported streams to Kotlin `Flow` with the SDK coroutine bridge.

## Platform Surface

| Surface | Public shape | Notes |
| - | - | - |
| Live object | `Flowable<T>` | Repository methods such as `AmitySocialClient.newPostRepository().getPost(postId)`. |
| Paged live collection | `Flowable<PagingData<T>>` | Query builders such as `getPosts().targetCommunity(...).build().query()`. |
| Finite live collection | `Flowable<List<T>>` | Used by selected APIs such as get-by-IDs style queries. |
| Coroutine bridge | `Flowable<T>.asFlow()` | Import `com.amity.socialcloud.sdk.helper.core.coroutines.asFlow`. |
| Cleanup | `Disposable.dispose()` or coroutine cancellation | Dispose or cancel when the Activity, Fragment, ViewModel, or UI scope no longer needs updates. |

## Parameters

| Parameter | Used by | Platforms | Description |
| - | - | - | - |
| `postId` or another entity ID | Live object methods | Android | ID of the object to observe. |
| Query builder target | Live collection builders | Android | Scope for the collection, such as `targetCommunity(communityId)` or `targetUser(userId)`. |
| `PagingData<T>` | Paged collections | Android | The emitted paging payload consumed by RecyclerView, Paging 3, or Compose paging. |
| `subscribeOn(Schedulers.io())` | RxJava streams | Android | Runs SDK work on an IO scheduler. |
| `observeOn(AndroidSchedulers.mainThread())` | UI observers | Android | Delivers callbacks on the Android main thread for UI updates. |

## Observe A Live Object

Observe a live object when your Android UI needs one SDK object to stay current after server or local-store changes.

<CodeGroup>
  ```kotlin Android theme={null}
  val disposable = AmitySocialClient.newPostRepository()
      .getPost(postId)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(
          { post: AmityPost ->
              showSuccessMessage(post.getPostId())
          },
          { error: Throwable ->
              handleGeneralError(error)
          }
      )

  disposable.dispose()
  ```
</CodeGroup>

## Observe A Paged Live Collection

The SDK query emits `PagingData<AmityPost>`. Feed it into your Paging 3 adapter or Compose paging collector.

<CodeGroup>
  ```kotlin Android theme={null}
  val disposable = AmitySocialClient.newPostRepository()
      .getPosts()
      .targetCommunity(communityId)
      .includeDeleted(false)
      .build()
      .query()
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(
          { pagingData: PagingData<AmityPost> ->
              showSuccessMessage(pagingData)
          },
          { error: Throwable ->
              handleGeneralError(error)
          }
      )

  disposable.dispose()
  ```
</CodeGroup>

## Convert to Kotlin Flow

Use the coroutine bridge when the rest of your app is built around Kotlin Flow.

<CodeGroup>
  ```kotlin Android theme={null}
  import com.amity.socialcloud.sdk.helper.core.coroutines.asFlow

  val postFlow = AmitySocialClient.newPostRepository()
      .getPost(postId)
      .asFlow()
  ```
</CodeGroup>

## Notes

* A live object fetches the server object and then observes the SDK local store. The internal live-object use case also checks tombstones for hard-deleted objects.
* Paged live collections use Android Paging 3, so page loading and UI load states should be handled through your Paging adapter or Compose paging integration.
* Dispose RxJava subscriptions in the matching lifecycle owner or ViewModel. For coroutines, cancel the collecting scope.
* Use `subscribeOn(Schedulers.io())` for SDK work and `observeOn(AndroidSchedulers.mainThread())` before mutating UI state.

## Related Topics

<CardGroup cols={2}>
  <Card title="Post Retrieval" icon="newspaper" href="/social-plus-sdk/social/content-management/posts/retrieval/get-post">
    See post-specific Android query examples.
  </Card>

  <Card title="Android Push Notifications" icon="bell" href="/social-plus-sdk/core-concepts/realtime-communication/push-notifications/setup/android-setup">
    Configure Android notification setup alongside real-time data.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.