AndroidRX - run method in background

前端 未结 5 1772
独厮守ぢ
独厮守ぢ 2021-02-12 15:38

I created simple activity with infinity progres bar, and I\'am trying to run time consuming method using RxJava to prevent UI thread from blocking, but everytime UI thread is bl

5条回答
  •  眼角桃花
    2021-02-12 16:08

    According to docs

    Deprecated: fromFunc0 Unnecessary now that Func0 extends Callable. Just call fromCallable(java.util.concurrent.Callable) instead.

    So you could make the call in this way:

    Observable.fromCallable(new Callable() {
                @Override
                public Object call() throws Exception {
                    return someMethod();
                }
            }).subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1() {
                        @Override
                        public void call(Object object) {
    
                        }
                    });
    
        

    提交回复
    热议问题