rx-android

Callback Hell: Sequencing RESTful Volley requests? RxAndroid?

可紊 提交于 2019-12-06 10:26:14
问题 I'd like to see an Android java example of how to sequence a chain of async (= nonblocking) RESTful Volley requests. Is this what RxAndroid is used for? If so, I'd like to see the example using RxAndroid. If not, I'd still like to see a good example w/out diving into CALLBACK HELL! I tried to do so but ended up in CBHell: Need to send multiple Volley Requests - in a sequence I want my result from my 1st request to be used in the 2nd request. Then the result from the 2nd request I want used in

RxJava - ConnectableObservable, disconnecting and reconnecting

心已入冬 提交于 2019-12-06 09:28:37
I am trying to replicate sample code from the "Disconnecting" section here . Disconnecting As we saw in connect's signature, this method returns a Subscription, just like Observable.subscribe does. You can use that reference to terminate the ConnectableObservable's subscription. That will stop events from being propagated to observers but it will not unsubscribe them from the ConnectableObservable. If you call connect again, the ConnectableObservable will start a new subscription and the old observers will begin receiving values again. ConnectableObservable<Long> connectable = Observable

How to cancel individual network request in Retrofit with RxJava?

╄→гoц情女王★ 提交于 2019-12-06 09:23:13
I am downloading some files from the network using retrofit and rxjava. In my app, the user may cancel the download. Pseudo Code: Subscription subscription = Observable.from(urls) .concatMap(this::downloadFile) .subscribe(file -> addFileToUI(file), Throwable::printStackTrace); Now, If I unsubscribe this subscription, then all requests get canceled. I want to download one by one, that's why used concatMap. How do I cancel particular request? There is a mechanism to cancel individual flows by external stimulus: takeUntil . You have to use some external tracking for it though: ConcurrentHashMap

How to terminate an Observable?

强颜欢笑 提交于 2019-12-06 06:43:56
问题 I have an Observable that I want to terminate if a certain condition is not met (that is if the response from a certain website is unsuccessful), so that I can re-query the website, and call the observable again. How do I go about doing it? Here's what I want to do: Observable.create(new Observable.OnSubscribe<String>() { @Override public void call(Subscriber<? super String> subscriber) { //Perform network actions here if (!response.isSuccessful()) { //terminate this Observable so I can

How to observe network changes in RxAndroid

六眼飞鱼酱① 提交于 2019-12-06 04:18:36
问题 I’m using the code given here. I put those code blocks as classes in my project’s util package. And then in the main activity class I wrote this.. class MenuActivity { // Variable declaration private final CompositeSubscription mConnectionSubscription = new CompositeSubscription(); @Override protected void onCreate(Bundle savedInstanceState) { // Some initialisation of UI elements done here mConnectionSubscription.add(AppObservable.bindActivity(this, NetworkUtils.observe(this)).subscribe(new

How do I handle response errors using with Retrofit and RxJava/RxAndroid?

杀马特。学长 韩版系。学妹 提交于 2019-12-06 03:14:43
I am having trouble working out how to handle a response error with retrofit and RxAndroid. onError() gets called if there is a network error or the like but I need to be able to get the response to check if there was an authentication error. Instead what I get is a token with a null String and I can't find out why. What is the best way to go about this? This is my RxAndroid call at the moment. Client.getInstance().getService() .getToken(usernameET.getText().toString(), passwordET.getText().toString()) .subscribe(new Subscriber<SiteInfo>() { @Override public void onCompleted() { } @Override

RxAndroid: UI changes on Schedulers.io() thread

人盡茶涼 提交于 2019-12-06 03:14:02
问题 I have simple job on IO thread which is changing home screen wallpaper, after that I'm trying to run some animation on UI thread: AppObservable.bindFragment(this, Observable.just(0)) .observeOn(Schedulers.io()) .subscribe(v -> setWallpaperOnSeparateThread()); private void setWallpaperOnSeparateThread() { WallpaperHelper.setBitmapAsWallpaper(photoViewAttacher.getVisibleRectangleBitmap(), getBaseActivity()); AppObservable.bindFragment(this, Observable.just(0)) .delay(500, TimeUnit.MILLISECONDS)

Retrofit 2 + RxAndroid: Handle Errors (4xx and some 200)

冷暖自知 提交于 2019-12-06 02:31:29
I saw a lot of articles and questions about error handling using retrofit combined with RxAndroid, but i am not able to set my configuration right. What do I want to accomplish: when receiving a 4xx code: handle it on onError() when receiving a 2xx code: -> try to parse to expected response and deliver it onNext() -> If not possible try to convert the JSON answer to MyAPIError class (simple POJO with errorNum and message) and deliver it on onError. So either 2xx or 4xx http codes might end up in onError(). What do I have at the moment: ServiceGenerator.java public class ServiceGenerator {

RxAndroid Release Apk is not working for build 25.0.2

五迷三道 提交于 2019-12-05 19:10:11
I have posted this on rxandroid issue page too but no response its been 4 days but no response , problem is in debug apk rxjava functionalities are working as expected , but in release apk , only functionalities related to rxjava or rxandroid are not working at all build.gradle(project) apply plugin: 'com.android.application' //or apply plugin: 'java' apply plugin: 'me.tatarka.retrolambda' apply plugin: 'com.jakewharton.hugo' apply plugin: 'android-apt' def AAVersion = '4.1.0' android { compileSdkVersion 25 buildToolsVersion '25.0.2' defaultConfig { applicationId "com.jutt.example1"

Flatten Observable<Observable<Cursor>> to Observable<Cursor>

五迷三道 提交于 2019-12-05 13:29:15
I've an Observable that returns a single Cursor instance ( Observable<Cursor> ). I'm trying to utilize ContentObservable.fromCursor to obtain every cursor's row in onNext callback. One of the solutions I've figured out is such construction: ContentObservable.fromCursor(cursorObservable.toBlocking().first()) .subscribe(cursor -> { // map to object // add to outer collection }, e -> {}, () -> { // do something with list of objects (outer collection) }); This looks rather like a hack because of toBlocking().first() , but it works. I don't like it because most of the processing is done in onNext