安卓怎么用rxjava实现线程间的传递数据
答案:2 悬赏:70 手机版
解决时间 2021-02-24 05:03
- 提问者网友:孤山下
- 2021-02-23 18:26
安卓怎么用rxjava实现线程间的传递数据
最佳答案
- 五星知识达人网友:醉吻情书
- 2021-02-23 20:02
erride
public void getPlaceAndWeatherData(String place) {
mMainView.showProgress();
PlaceRepository repository = new PlaceRepository();
Context context = BaseApplication.getInstance();
Observable placeObservable = repository.getPlaceList(context);
Observable weatherObservable = ServiceManager.getInstance().getApiService().getWeatherInfo(place, Constants.BAIDU_AK);
Observable.merge(placeObservable, weatherObservable)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber
public void getPlaceAndWeatherData(String place) {
mMainView.showProgress();
PlaceRepository repository = new PlaceRepository();
Context context = BaseApplication.getInstance();
Observable placeObservable = repository.getPlaceList(context);
Observable weatherObservable = ServiceManager.getInstance().getApiService().getWeatherInfo(place, Constants.BAIDU_AK);
Observable.merge(placeObservable, weatherObservable)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber
全部回答
- 1楼网友:愁杀梦里人
- 2021-02-23 20:40
importjava.util.scanner;publicclasstest { publicstaticvoidmain(string[]args) { finalmessagemessage=newmessage();finalthreadthread=newthread(newrunnable(){ publicvoidrun(){ scannerscanner=newscanner(system.in); while(true){ stringmsg=scanner.next(); if(msg.equals("exit")) return; message.sendmessage(msg); } } }); thread.start();while(true){ if(thread.isalive()==false) break; stringmsg=message.receivemessage(); if(msg!=null){ system.out.println(msg); } try{ thread.sleep(100); }catch(interruptedexceptione){} }} }classmessage{ privatestringmessage; privatebooleanunread=false; synchronizedvoidsendmessage(stringmessage){ this.message=message; unread=true; }synchronizedstringreceivemessage(){ stringmsg=unread?message:null; unread=false; returnmsg; } }
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯