RxJava Reactivex. Flowable use

Source: Internet
Author: User

/**
* Load local resources and display the controls, which can be used for any more time-consuming requests
*/

private void Setimageresource (int resourceId) {
Flowable.just (RESOURCEID)
. Subscribeon (Schedulers.io ())
Parameter type return value
. Map (new Function<integer, bitmap> () {
@Override
Public Bitmap apply (@NonNull integer integer) throws Exception {
Return Bitmaputils.createcircleimage (Bitmapfactory.decoderesource (MainActivity.this.getResources (), integer));;
return null;
}
})
Event Subscription Results returned
. Subscribe (New consumer<bitmap> () {
@Override
public void Accept (@NonNull Bitmap Bitmap) throws Exception {

}
});
}

/**
* No time consuming operation to request parameters
*/
public void Create () {
Flowable.create (New flowableonsubscribe<integer> () {
@Override
public void Subscribe (flowableemitter<integer> e) throws Exception {
Events to execute
E.onnext (Griddingdatabase.getinstance (). Problemtypedao (). GetSize ());
E.oncomplete ();
}
}, Backpressurestrategy.error)
. Subscribeon (Schedulers.io ())
. Observeon (Schedulers.io ())
. Subscribe (New consumer<integer> () {
@Override
public void Accept (@NonNull integer integer) throws Exception {

}
});
}

/**
* Traverse list to extract a certain condition of the bean
*/
private void list (list<staffinfo> staffinfolist) {
Flowable.fromiterable (Staffinfolist)
. Filter (New predicate<staffinfo> () {
@Override
public boolean test (@NonNull staffinfo staffinfo) throws Exception {
return staffinfo.ischecked ();
}
}). Subscribe (New consumer<staffinfo> () {
@Override
public void Accept (@NonNull staffinfo staffinfo) throws Exception {

}
});
}

/**
* Traverse List
*/
private void Forlist (list<staffinfo> staffinfolist) {
Flowable.just (Staffinfolist)
. FLATMAP (new Function<list<staffinfo>, publisher<staffinfo>> () {
@Override
Public publisher<staffinfo> Apply (@NonNull list<staffinfo> staffinfolist) throws Exception {
Return flowable.fromiterable (staffinfolist);
}
})
. Subscribe (New consumer<staffinfo> () {
@Override
public void Accept (@NonNull staffinfo staffinfo) throws Exception {

}
});
}

RxJava Reactivex. Flowable use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.