rx.Observable.unsubscribeOn()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中rx.Observable.unsubscribeOn()方法的一些代码示例,展示了Observable.unsubscribeOn()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.unsubscribeOn()方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:unsubscribeOn

Observable.unsubscribeOn介绍

[英]Modifies the source Observable so that subscribers will unsubscribe from it on a specified Scheduler. Scheduler: you specify which Scheduler this operator will use
[中]修改可观察的源,以便订阅者在指定的计划程序上取消订阅。调度器:指定该操作员将使用的调度器

代码示例

代码示例来源:origin: bumptech/glide

@Override
protected void onDestroy() {
 super.onDestroy();
 fetchImagesObservable.unsubscribeOn(AndroidSchedulers.mainThread());
}

代码示例来源:origin: pinguo-zhouwei/MZBannerView

/**
 *
 * @param observable
 * @param <T>
 * @return
 */
protected  <T> Observable<T> observe(Observable<T> observable){
  return observable.subscribeOn(Schedulers.io())
      .unsubscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread());
}

代码示例来源: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: Rukey7/MvpApp

/**
 * 获取图片列表
 * @return
 */
public static Observable<List<PhotoInfo>> getPhotoList() {
  return sNewsService.getPhotoList()
      .subscribeOn(Schedulers.io())
      .unsubscribeOn(Schedulers.io())
      .subscribeOn(AndroidSchedulers.mainThread())
      .observeOn(AndroidSchedulers.mainThread());
}

代码示例来源:origin: Rukey7/MvpApp

/**
 * 获取更多图片列表
 * @return
 */
public static Observable<List<PhotoInfo>> getPhotoMoreList(String setId) {
  return sNewsService.getPhotoMoreList(setId)
      .subscribeOn(Schedulers.io())
      .unsubscribeOn(Schedulers.io())
      .subscribeOn(AndroidSchedulers.mainThread())
      .observeOn(AndroidSchedulers.mainThread());
}

代码示例来源:origin: Rukey7/MvpApp

@Override
  public Observable<T> call(Observable<Map<String, List<T>>> mapObservable) {
    return  mapObservable.flatMap(new Func1<Map<String, List<T>>, Observable<T>>() {
      @Override
      public Observable<T> call(Map<String, List<T>> stringListMap) {
        if (TextUtils.isEmpty(mMapKey)) {
          return Observable.error(new Throwable("Map Key is empty"));
        }
        return Observable.from(stringListMap.get(mMapKey));
      }
    }).subscribeOn(Schedulers.io())
        .unsubscribeOn(Schedulers.io())
        .subscribeOn(AndroidSchedulers.mainThread())
        .observeOn(AndroidSchedulers.mainThread());
  }
}

代码示例来源:origin: Rukey7/MvpApp

/**
 * 获取视频列表
 * @return
 */
public static Observable<List<VideoInfo>> getVideoList(String videoId, int page) {
  return sNewsService.getVideoList(videoId, page * INCREASE_PAGE / 2)
      .subscribeOn(Schedulers.io())
      .unsubscribeOn(Schedulers.io())
      .subscribeOn(AndroidSchedulers.mainThread())
      .observeOn(AndroidSchedulers.mainThread())
      .flatMap(_flatMapVideo(videoId));
}

代码示例来源:origin: Rukey7/MvpApp

/**
 * 获取图集
 * @param photoId 图集ID
 * @return
 */
public static Observable<PhotoSetInfo> getPhotoSet(String photoId) {
  return sNewsService.getPhotoSet(StringUtils.clipPhotoSetId(photoId))
      .subscribeOn(Schedulers.io())
      .unsubscribeOn(Schedulers.io())
      .subscribeOn(AndroidSchedulers.mainThread())
      .observeOn(AndroidSchedulers.mainThread());
}

代码示例来源:origin: Rukey7/MvpApp

/**
 * 获取美女图片
 * 注: 因为网易这个原接口参数一大堆,我只传了部分参数,返回的数据会出现图片重复的情况,请不要在意这个问题- -
 * @return
 */
public static Observable<List<BeautyPhotoInfo>> getBeautyPhoto(int page) {
  return sNewsService.getBeautyPhoto(page * INCREASE_PAGE)
      .subscribeOn(Schedulers.io())
      .unsubscribeOn(Schedulers.io())
      .subscribeOn(AndroidSchedulers.mainThread())
      .observeOn(AndroidSchedulers.mainThread())
      .flatMap(_flatMapPhotos());
}

代码示例来源: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: Rukey7/MvpApp

/**
 * 获取专题数据
 * @param specialId
 * @return
 */
public static Observable<SpecialInfo> getSpecial(String specialId) {
  return sNewsService.getSpecial(specialId)
      .subscribeOn(Schedulers.io())
      .unsubscribeOn(Schedulers.io())
      .subscribeOn(AndroidSchedulers.mainThread())
      .observeOn(AndroidSchedulers.mainThread())
      .flatMap(_flatMapSpecial(specialId));
}

代码示例来源:origin: Rukey7/MvpApp

/**
 * 获取新闻详情
 * @param newsId 新闻ID
 * @return
 */
public static Observable<NewsDetailInfo> getNewsDetail(final String newsId) {
  return sNewsService.getNewsDetail(newsId)
      .subscribeOn(Schedulers.io())
      .unsubscribeOn(Schedulers.io())
      .subscribeOn(AndroidSchedulers.mainThread())
      .observeOn(AndroidSchedulers.mainThread())
      .flatMap(new Func1<Map<String, NewsDetailInfo>, Observable<NewsDetailInfo>>() {
        @Override
        public Observable<NewsDetailInfo> call(Map<String, NewsDetailInfo> newsDetailMap) {
          return Observable.just(newsDetailMap.get(newsId));
        }
      });
}

代码示例来源:origin: Rukey7/MvpApp

/**
 * 获取新闻列表
 * @return
 */
public static Observable<NewsInfo> getNewsList(String newsId, int page) {
  String type;
  if (newsId.equals(HEAD_LINE_NEWS)) {
    type = "headline";
  } else {
    type = "list";
  }
  return sNewsService.getNewsList(type, newsId, page * INCREASE_PAGE)
      .subscribeOn(Schedulers.io())
      .unsubscribeOn(Schedulers.io())
      .subscribeOn(AndroidSchedulers.mainThread())
      .observeOn(AndroidSchedulers.mainThread())
      .flatMap(_flatMapNews(newsId));
}

代码示例来源:origin: Rukey7/MvpApp

/**
   * 倒计时
   * @param time
   * @return
   */
  public static Observable<Integer> countdown(int time) {
    if (time < 0) {
      time = 0;
    }
    final int countTime = time;

    return Observable.interval(0, 1, TimeUnit.SECONDS)
        .map(new Func1<Long, Integer>() {
          @Override
          public Integer call(Long increaseTime) {
            return countTime - increaseTime.intValue();
          }
        })
        .take(countTime + 1)
        .subscribeOn(Schedulers.io())
        .unsubscribeOn(Schedulers.io())
        .subscribeOn(AndroidSchedulers.mainThread())
        .observeOn(AndroidSchedulers.mainThread());

  }
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

@NonNull
private Drawable getDrawableFromNet(final String source) {
  mSubscription = Api.getDefault(HostType.NEWS_DETAIL_HTML_PHOTO)
      .getNewsBodyHtmlPhoto(Api.getCacheControl(),source)
      .unsubscribeOn(Schedulers.io())
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .map(new Func1<ResponseBody, Boolean>() {
        @Override
        public Boolean call(ResponseBody response) {
          return WritePicToDisk(response, source);
        }
      }).subscribe(new Subscriber<Boolean>() {
        @Override
        public void onCompleted() {
        }
        @Override
        public void onError(Throwable e) {
        }
        @Override
        public void onNext(Boolean isLoadSuccess) {
          mPicCount++;
          if (isLoadSuccess && (mPicCount == mPicTotal - 1)) {
            mTextView.setText(Html.fromHtml(mNewsBody, URLImageGetter.this, null));
          }
        }
      });
  return createPicPlaceholder();
}

代码示例来源:origin: lyft/scoop

public <T> void add(Observable<T> observable, Observer<? super T> observer) {
  if (Looper.myLooper() != Looper.getMainLooper()) { throw new AssertionError("Must be on main thread"); }
  this.subscriptions.add(observable.subscribeOn(this.subscribeOnScheduler)
      .observeOn(this.observeOnScheduler)
      .unsubscribeOn(this.observeOnScheduler)
      .subscribe(observer));
}

代码示例来源:origin: GeekGhost/Ghost

/**
 * ClassificationPresenter
 *
 * @return
 */
public Observable<VideoRes> queryClassification() {
  return mService.getHomePage()
      .map(new ServerResultFunc<VideoRes>())
      .onErrorResumeNext(new HttpResultFunc<VideoRes>())
      .subscribeOn(Schedulers.io())
      .unsubscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread());
}

代码示例来源:origin: kaku2015/ColorfulNews

mSubscription = RetrofitManager.getInstance(HostType.NEWS_DETAIL_HTML_PHOTO)
    .getNewsBodyHtmlPhoto(source)
    .unsubscribeOn(Schedulers.io())
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())

代码示例来源:origin: devinhu/androidone

public void toSubscribe(Observable observable, Subscriber subscriber){
    observable.subscribeOn(Schedulers.io())
        .unsubscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(subscriber);
  }
}

代码示例来源:origin: NielsMasdorp/Speculum-Android

@Override
public void loadCalendarEvents(int updateDelay, Subscriber<String> subscriber) {
  compositeSubscription.add(Observable.interval(0, updateDelay, TimeUnit.MINUTES)
      .flatMap(ignore -> googleCalendarService.getCalendarEvents())
      .retryWhen(Observables.exponentialBackoff(AMOUNT_OF_RETRIES, DELAY_IN_SECONDS, TimeUnit.SECONDS))
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeOn(Schedulers.io())
      .unsubscribeOn(Schedulers.io())
      .subscribe(subscriber));
}

相关文章

Observable类方法