You can visit ReactiveX for more information.
How it Works
SDK handles lots of data received from various sources. Data can be present in local cache. It might also be queried from the server or received from some real-time events. What this means is that same data is constantly updating. The data that you are accessing at the moment can get updated by other sources and becomes out of sync. Rx3 Data Stream helps in syncing the data so you will always get the most recent one. Whenever the data updates, you will be notified through Flowable Objects and Flowable Collection. New data gets automatically collected everytime when there is an updation and user need not refresh to get the recent data.Data Sources
Local Cache
Data present in local storage
Server Queries
Data queried from the server
Real-time Events
Data received from real-time events
How to Retrieve Data from Rx3 Data Stream
To retrieve data from the RxStream, we need to subscribe to the Stream(Flowable/Single/Completable) by defining subscribing and observing threads.Events a Data Stream can Emit
In the RxJava3 framework we have these different types of objects that can be observed:Flowable
Emits a stream of elements- doOnNext
- doOnError
Single
Emits exactly one element- doOnSuccess
- doOnError
Completable
Emits a “complete” event, without emitting any data type, just a success/failure- doOnComplete
- doOnError
Flowable Usage
Flowable Usage
Single Usage
Single Usage
Completable Usage
Completable Usage
Flow functions
By using the.asFlow()
method, it enables the conversion of Flowable<T> functions of the Amity Android SDK into Flow functions.
Jetpack Compose compatibility
Amity Android SDK seamlessly integrates with Jetpack Compose UI, allowing you to take full advantage of the modern UI toolkit provided by Jetpack Compose. You can effortlessly incorporate our SDK into your Jetpack Compose-based projects to enhance your app’s social experience. This compatibility ensures that you can leverage the power of Jetpack Compose while benefiting from the features and capabilities our SDK provides.Flow of PagingData in Compose
In Jetpack Compose, integrating data from aFlow<PagingData<T>>
source into your UI is made easy through the collectAsLazyPagingItems()
function. This function allows you to seamlessly paginate and display items within your Composable functions.
To start using it, add compose paging dependency in your project app level build.gradle file.
Flow in Compose
By usingcollectAsState()
method, it can deliver asynchronous data updates to your Compose UI components.
Best Practices
Resource Management
Resource Management
Proper Disposal: Always dispose of RxJava subscriptions to prevent memory leaks when Activities/Fragments are destroyed.
Thread Management
Thread Management
Proper Scheduling: Use
subscribeOn(Schedulers.io())
for background operations and observeOn(AndroidSchedulers.mainThread())
for UI updates.Error Handling
Error Handling
Graceful Recovery: Implement robust error handling with
doOnError
for all RxJava streams to prevent crashes.Jetpack Compose Integration
Jetpack Compose Integration
State Management: Use
collectAsState()
for single objects and collectAsLazyPagingItems()
for paginated collections in Compose.