Я получаю ниже предупреждающие сообщения, и после того, как иногда приложение выдает ANR dailog box
Skipped 368 frames! The application may be doing too much work on its main thread.
Я использую плавный поток для реализации бесконечной прокрутки с recycler view
.
Я перепробовал много вещей, но не работал.
Ниже мой код:
private void prepareData() {
pagination = PublishProcessor.create();
compositeDisposable = new CompositeDisposable();
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
isScrolling = true;
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
currentStories = mLayoutManager.getChildCount();
totalStories = mLayoutManager.getItemCount();
scrolledStories = ((GridLayoutManager) mLayoutManager).findFirstVisibleItemPosition();
if (!requestOnWay && (currentStories + scrolledStories == totalStories)) {
pagination.onNext(mAdapter.getLastVisibleItemId());
}
}
});
Disposable disposable = pagination.onBackpressureDrop()
.doOnNext(integer -> {
requestOnWay = true;
mAdapter.showLoader(true);
})
.concatMap((Function<Integer, Publisher<Response<News>>>) NewsFragment.this::getNews)
.observeOn(AndroidSchedulers.mainThread())
.doOnNext(newsResponse -> {
if (newsResponse.isSuccessful() && newsResponse.body() != null) {
processData(newsResponse.body());
} else {
Log.e(TAG, newsResponse.code() + " " + newsResponse.message());
}
requestOnWay = false;
mAdapter.showLoader(false);
})
.doOnError(throwable -> {
if (throwable instanceof HttpException) {
Response<?> response = ((HttpException) throwable).response();
Log.d(TAG, response.message());
} else if (throwable instanceof UnknownHostException) {
Log.d(TAG, "News On error handling");
updateEmptyView(null);
}
})
.subscribe();
RxJavaPlugins.setErrorHandler(Functions.<Throwable>emptyConsumer());
compositeDisposable.add(disposable);
pagination.onNext(0);
}
private Flowable<Response<News>> getNews(int fromId) {
return applicationComponent.getNetwork().getNews(token, pageCount, PAGE_LIMIT)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
Заранее спасибо