Deprecated
The newer live data offers a better solution to this problem. If you're interested in using rx with live data, you can checkout the live data from reactive streams api
RxLoader
compose()
your Observable
s and Single
s into ones that load data that's cached across activity orientation changes without leaking your Activity
and without you having to worry about unsubscribing.
RxLoader accomplishes this by building on top of Android Loaders, so the library is super lightweight (only defines 47 methods).
There's a lot of data loading solutions already for Android. I detail why I felt we needed another one here
Code
Github repo is here. Note that it contains some rough sample code.
Javadoc
Basic Usage
build.gradle
dependencies {
compile 'com.philosophicalhacker.rxloader:rxloader:0.4.0'
}
FooActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
final RxLoader rxLoader = new RxLoader(this, getSupportLoaderManager());
storyApiService
.getAskStories()
.compose(rxLoader.<List<Integer>>makeSingleTransformer())
.subscribe(new Consumer<List<Integer>>() {
@Override public void accept(List<Integer> integers) {
Log.d(TAG, "call() called with: integers = [" + integers + "]");
}
});
}
Notice that you don't have worry about calling subscribeOn
or observeOn
either. That's handled by RxLoader.
License
Copyright 2017 Kevin Matthew Dupree
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.