rx-android

How to use rx java's interval for background task

二次信任 提交于 2019-12-11 10:22:28
问题 According to https://github.com/ReactiveX/RxAndroid/issues/257#issuecomment-164263215 . interval is just for active code, and if app is not wake up, it will not work. So how to use interval for background scheduling tasks? 回答1: Please DO NOT use this solution: To use interval from RxJava you'll have to make sure your app's process stays alive. One way to do it is to put use the Observable in a foreground service. This is a bad idea because the service is NOT actively delivering value to the

RxAndroidBle - Auto connect issue

拈花ヽ惹草 提交于 2019-12-11 09:48:00
问题 I am using RxAndroidBle library: This code is working fine as expected, on click of Connect button on UI, it establishes connection. Issue coming up when I wanted the auto-connect to the device when the device comes back to range. I don’t want to click on Connect button again. is there any functionality exists like that ? does ’true’ flag helps me here, if yes, how to implement it ? Suggestion please. rxBleDevice.establishConnection(true); If I use rxBleDevice.establishConnection(true) ,

Querying single database row using rxjava2

徘徊边缘 提交于 2019-12-11 05:51:56
问题 I am using rxjava2 for the first time on an Android project, and am doing SQL queries on a background thread. However I am having trouble figuring out the best way to do a simple SQL query, and being able to handle the case where the record may or may not exist. Here is the code I am using: public Observable<Record> createRecordObservable(int id) { Callable<Record> callback = new Callable<Record>() { @Override public Record call() throws Exception { // do the actual sql stuff, e.g. // select

rxJava Observer.onNext not called second time

允我心安 提交于 2019-12-11 05:01:32
问题 I am using rxJava to fetch data from the database and show it in a recyclerview. The relevant code is shown below function updateUI(){ ContactsLab contactsLab = ContactsLab.get(getActivity()); Subscription sub = contactsLab.getContactList().subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .toList() .subscribe(onContactsReceived()); mCompositeSubscription.add(sub); } ContactsLab is a singleton that returns an Observable of Contact objects. onContactsReceived function is

Issue with PublishSubject and TestScheduler, item isn't emitted

孤者浪人 提交于 2019-12-11 02:56:08
问题 I have been facing an issue with subjects and TestSchedulers. My tests pass if I use a Trampoline scheduler but for some reason they fail if I use the TestScheduler. Here's my sample test and relevant classes. @RunWith(MockitoJUnitRunner::class) class DemoViewModelTest { //Error Mocks private val actionsStream: PublishSubject<DemoContract.ViewEvent> = PublishSubject.create() private lateinit var viewModel: DemoViewModel private val handler = mock(DemoContract.Handler::class.java) @Before fun

RXjava and Retrofit to handle empty data response

て烟熏妆下的殇ゞ 提交于 2019-12-11 00:48:15
问题 I use Rxjava and Retrofit to handle the response from a http server. Most of the time, data response is in this format: { code: 'OK', data: {.....} } and sometimes, the data property doesn't exist. { code: 'OK' } I make a BaseResponse class. public class BaseResponse<T> implements Serializable { private String code; private String msg; private T data; public String getCode() { return code; } public String getMsg() { return msg; } public T getData() { return data; } } and make a Map function

How to manage Looper thread needed in RxJava

你离开我真会死。 提交于 2019-12-10 23:16:54
问题 I want to encapsulate in an Observable a logic that queries a ContentProvider and also subscribes ContentProvider cursor to supply continuous updates. As the observable does IO work I need to subscribe it in Schedulers.io() . The problem with that is that then I can't register a ContentObserver because it needs a looper prepared thread. What is the recommended way to manage that and encapsulate it in a single Observable . Code to illustrate that: public Observable<Integer>

How to release an android SDK with third party dependencies?

梦想与她 提交于 2019-12-10 19:17:32
问题 I developed an android SDK to consume our restful API. I used third party libraries like retrofit2 and rxandroid in my SDK. dependencies { compile 'io.reactivex:rxandroid:1.2.1' compile 'com.squareup.retrofit2:retrofit:2.0.2' compile 'com.squareup.retrofit2:converter-gson:2.0.2' compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2' } I released an aar file to my customer. His app imported my aar file and direct used my service which is implemented by retrofit2 to consume APIs. The problem is

Clicking back button twice to exit an activity with rxjava

旧时模样 提交于 2019-12-10 17:57:15
问题 Looking for a subtle rx approach to exit an activity while pressing back button two times. boolean doubleBackToExitPressedOnce = false; @Override public void onBackPressed() { if (doubleBackToExitPressedOnce) { super.onBackPressed(); return; } this.doubleBackToExitPressedOnce = true; Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show(); new Handler().postDelayed(new Runnable() { @Override public void run() { doubleBackToExitPressedOnce=false; } }, 2000); } 回答1: I

RxJava - ConnectableObservable, disconnecting and reconnecting

落爺英雄遲暮 提交于 2019-12-10 10:29:32
问题 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