Support Rx Java
Most of APIs from Qiscus Chat SDK are using RxJava, but no worry, it's easy to use RxJava method. You just need to call subscribe() after you call the method. The main advantage of using RxJava is easiness of creating asynchronous method. You just need to add subscribeOn() where its thread will be used to run the task and observeOn() where its thread will be used to deliver result. To learn more about RxJava you can visit this page. This is an example on how to use RxJava method from QiscusApi.
For example get a Nonce:
QiscusApi.getInstance().getJWTNonce();
To execute it, you can call it like this:
QiscusApi.getInstance().getJWTNonce()
.subscribeOn(Schedulers.io()) // need to run this task on IO thread
.observeOn(AndroidSchedulers.mainThread()) // deliver result on main thread or UI thread
.subscribe(qiscusNonce -> {
// on success
}, throwable -> {
// on error
});
But if you don't want to use Rx Java you can use QiscusRxExecutor, for example:
x
QiscusRxExecutor.execute(QiscusApi.getInstance().getJWTNonce(),
new QiscusRxExecutor.Listener<QiscusNonce>() {
public void onSuccess(QiscusNonce qiscusNonce) {
// on success
}
public void onError(Throwable throwable) {
// on error
}
});
Was this page helpful?