本文整理了Java中rx.Observable.observeOn()
方法的一些代码示例,展示了Observable.observeOn()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.observeOn()
方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:observeOn
[英]Modifies an Observable to perform its emissions and notifications on a specified Scheduler, asynchronously with an unbounded buffer.
Scheduler: you specify which Scheduler this operator will use
[中]修改Observable,以在指定的调度程序上使用无限缓冲区异步执行其发射和通知。
调度器:指定该操作员将使用的调度器
代码示例来源:origin: square/retrofit
@Override public Object adapt(Call<Object> call) {
// Delegate to get the normal Observable...
Observable<?> o = delegate.adapt(call);
// ...and change it to send notifications to the observer on the specified scheduler.
return o.observeOn(scheduler);
}
代码示例来源:origin: greenrobot/greenDAO
private void updateNotes() {
notesQuery.list()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<Note>>() {
@Override
public void call(List<Note> notes) {
notesAdapter.setNotes(notes);
}
});
}
代码示例来源:origin: greenrobot/greenDAO
private void addNote() {
String noteText = editText.getText().toString();
editText.setText("");
final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
String comment = "Added on " + df.format(new Date());
Note note = new Note(null, noteText, comment, new Date(), NoteType.TEXT);
noteDao.insert(note)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Note>() {
@Override
public void call(Note note) {
Log.d("DaoExample", "Inserted new note, ID: " + note.getId());
updateNotes();
}
});
}
代码示例来源:origin: cymcsg/UltimateAndroid
private <T> void toSubscribe(Observable<T> o, Subscriber<T> s) {
o.subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s);
}
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
public void downloadFile(View view) {
subscription = getObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(getObserver());
}
}
代码示例来源:origin: GitLqr/LQRWeChat
private void setQRCode(String content) {
Observable.just(QRCodeEncoder.syncEncodeQRCode(content, UIUtils.dip2Px(100)))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(bitmap -> mIvCard.setImageBitmap(bitmap), this::loadQRCardError);
}
代码示例来源:origin: Rukey7/MvpApp
/**
* 获取福利图片
* @return
*/
public static Observable<WelfarePhotoInfo> getWelfarePhoto(int page) {
return sWelfareService.getWelfarePhoto(page)
.subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io())
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.flatMap(_flatMapWelfarePhotos());
}
代码示例来源:origin: bumptech/glide
@Override
protected void onCreate(Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
adapter = new ImgurImageAdapter();
recyclerView.setAdapter(adapter);
fetchImagesObservable
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<List<Image>>() {
@Override
public void onCompleted() { }
@Override
public void onError(Throwable e) { }
@Override
public void onNext(List<Image> images) {
adapter.setData(images);
}
});
}
代码示例来源:origin: greenrobot/greenDAO
@Override
public void onNoteClick(int position) {
Note note = notesAdapter.getNote(position);
final Long noteId = note.getId();
noteDao.deleteByKey(noteId)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Void>() {
@Override
public void call(Void aVoid) {
Log.d("DaoExample", "Deleted note, ID: " + noteId);
updateNotes();
}
});
}
};
代码示例来源:origin: HotBitmapGG/bilibili-android-client
private void getTags() {
RetrofitHelper.getSearchAPI()
.getHotSearchTags()
.compose(bindToLifecycle())
.map(HotSearchTag::getList)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(listBeans -> {
hotSearchTags.addAll(listBeans);
initTagLayout();
}, throwable -> {
});
}
代码示例来源:origin: GitLqr/LQRWeChat
public void resetDraft() {
Observable.just(RongIMClient.getInstance().getTextMessageDraft(mConversationType, mSessionId))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> {
if (!TextUtils.isEmpty(s)) {
getView().getEtContent().setText(s);
RongIMClient.getInstance().clearTextMessageDraft(mConversationType, mSessionId);
}
}, this::loadError);
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
private void setUpSplash() {
Observable.timer(2000, TimeUnit.MILLISECONDS)
.compose(bindToLifecycle())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aLong -> finishTask());
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
private void initRxBus() {
RxBus.getInstance().toObserverable(Integer.class)
.compose(bindToLifecycle())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::switchPager);
}
代码示例来源:origin: GitLqr/LQRWeChat
private void setToTop() {
Observable.just(RongIMClient.getInstance().getConversation(mConversationType, mSessionId))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(conversation -> {
if (conversation != null) {
getView().getSbToTop().setChecked(conversation.isTop());
}
});
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
@Override
public void loadData() {
RetrofitHelper.getLiveAPI()
.getLiveAppIndex()
.compose(bindToLifecycle())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(liveAppIndexInfo -> {
mLiveAppIndexAdapter.setLiveInfo(liveAppIndexInfo);
finishTask();
}, throwable -> {
});
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
@Override
protected void loadData() {
RetrofitHelper.getBiliAppAPI()
.getVideoDetails(av)
.compose(this.bindToLifecycle())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(videoDetails -> {
mVideoDetailsInfo = videoDetails.getData();
finishTask();
}, throwable -> {
});
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
@Override
public void loadData() {
RetrofitHelper.getBangumiAPI()
.getSeasonNewBangumiList()
.compose(bindToLifecycle())
.doOnSubscribe(this::showProgressBar)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(seasonNewBangumiInfo -> {
results.addAll(seasonNewBangumiInfo.getResult().subList(0,50));
finishTask();
}, throwable -> hideProgressBar());
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
@Override
protected void loadData() {
RetrofitHelper.getBiliAPI()
.getAttentionDynamic()
.compose(bindToLifecycle())
.map(attentionDynamicInfo -> attentionDynamicInfo.getData().getFeeds())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(feedsBeans -> {
dynamics.addAll(feedsBeans);
finishTask();
}, throwable -> initEmptyView());
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
public void getUserInfo() {
RetrofitHelper.getAccountAPI()
.getUserInfoById(mid)
.compose(this.bindToLifecycle())
.doOnSubscribe(this::showProgressBar)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(userInfo -> {
mUserDetailsInfo = userInfo;
finishTask();
}, throwable -> hideProgressBar());
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
@Override
protected void loadData() {
RetrofitHelper.getLiveAPI()
.getLiveAppIndex()
.compose(bindToLifecycle())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(liveAppIndexInfo -> {
mLiveAppIndexAdapter.setLiveInfo(liveAppIndexInfo);
finishTask();
}, throwable -> initEmptyView());
}
内容来源于网络,如有侵权,请联系作者删除!