我试图转换这个AsyncTask:
private static class UpdateFeedTask extends AsyncTask<Void, Void, Void> {
private WeakReference<FeedFragment> weakFeedFragment;
private UpdateFeedTask(FeedFragment feedFragment) {
this.weakFeedFragment = new WeakReference<>(feedFragment);
}
@Override
protected void onPreExecute() {
if (!weakFeedFragment.get().swipeRefreshLayout.isRefreshing()) {
weakFeedFragment.get().feedProgressBar.setVisibility(View.VISIBLE);
}
}
@Override
protected final Void doInBackground(Void... voids) {
weakFeedFragment.get().submissionList = weakFeedFragment.get().paginator.next();
return null;
}
@Override
protected void onPostExecute(Void value) {
weakFeedFragment.get().feedProgressBar.setVisibility(View.INVISIBLE);
weakFeedFragment.get().swipeRefreshLayout.setRefreshing(false);
weakFeedFragment.get().isLoadingNextSubmissions = false;
FeedAdapter feedAdapter = (FeedAdapter) weakFeedFragment.get().recyclerView.getAdapter();
feedAdapter.updateItems(weakFeedFragment.get().submissionList);
}
}
进入单个Observable,但是当我调用它时,它根本不会启动:
private void UpdateFeed() {
if (swipeRefreshLayout.isRefreshing()) {
feedProgressBar.setVisibility(View.VISIBLE);
}
updateFeedObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new SingleObserver<Listing<Submission>>() {
@Override public void onSubscribe(Disposable d) {
d.dispose();
}
@Override public void onSuccess(Listing<Submission> submissions) {
Log.d(TAG, "onSuccess: WORKS"); //Nope
feedProgressBar.setVisibility(View.INVISIBLE);
swipeRefreshLayout.setRefreshing(false);
isLoadingNextSubmissions = false;
FeedAdapter feedAdapter = (FeedAdapter) recyclerView.getAdapter();
feedAdapter.updateItems(submissions);
}
@Override public void onError(Throwable e) {
Log.e(TAG, e.getMessage());
}
});
}
public Single<Listing<Submission>> updateFeedObservable() {
return Single.defer(() -> Single.fromCallable(() -> {
Log.d(TAG, "updateFeedObservable: WORKS"); //Nope
return paginator.next();
}));
}
我尝试更改调度程序但据我所知,IO相关的任何内容都需要使用Schedulers.io 我不确定问题究竟在哪里,任何帮助都会受到赞赏
答案 0 :(得分:3)
在$ awk '{for(i=1; i<=NF; i++) if($i=="is") if(++count%3==0) $i="hat"}1' file
is this just real life or is this just fantasy or hat it just me
中,您立即致电new SingleObserver<Listing<Submission>>()::onSubscribe()
,这样您就永远无法接听d.dispose()
来电,因为当您订阅时,您将处置onSuccess()
。
删除:SingleObserver
还有:
d.dispose()
可以简化为:
return Single.defer(() -> Single.fromCallable(() -> {
Log.d(TAG, "updateFeedObservable: WORKS"); // Nope
return paginator.next();
}));