我是 or rxandroid 的新手rxjava,我想将我的AsyncTaskand 回调地狱更改为observableand subscriber。但我对此有一个问题。我需要对我的数据库发出两个请求。
我对第一个请求的响应将是第二个请求的结果。我尝试用 来解决这个问题flatMap。第一个请求返回值,一切正常,但下一个请求给我NetworkOnMainThreadException。
我知道该请求执行但main thread为什么?subscribeOn(Schedulers.io())我之前尝试添加flatMap但结果是相同的。你能帮我解释一下我做错了什么吗?提前致谢。我的代码……
private void getFavouriteList(){
Observable.create((Observable.OnSubscribe<PaginatedScanList<UserDO>>) subscriber -> {
final Map<String, AttributeValue> filterExpressionAttributeValues = new HashMap<>();
filterExpressionAttributeValues
.put(":val1", new AttributeValue().withS(sharedPreferences.getString("socialId", "")));
final DynamoDBScanExpression scanExpression = new DynamoDBScanExpression()
.withFilterExpression("socialId = :val1")
.withExpressionAttributeValues(filterExpressionAttributeValues);
PaginatedScanList<UserDO> result = dynamoDBMapper.scan(UserDO.class, scanExpression);
Log.d(TAG, "first result size " + result.size());
subscriber.onNext(result);
subscriber.onCompleted();
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.filter(result -> {
if(result.isEmpty()) {
Toast.makeText(context, "Can …Run Code Online (Sandbox Code Playgroud) 我有两个Recyclerview里面NestedScrollView.第二个Recyclerview也有SwipeRefreshLayout.我尝试为两个回收器设置一个滚动,但我的解决方案不起作用.两个回收器分开滚动,我没有解决方案,请帮助我.提前致谢.我的代码
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/noFriendsTitle"
android:layout_marginTop="@dimen/marginTop"
android:layout_centerHorizontal="true"
android:visibility="gone"
android:text="@string/no_friends_title"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBarGetFriends"
android:layout_centerInParent="true"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainFriendsRelative"
android:paddingTop="@dimen/marginTopSmall"
android:paddingBottom="@dimen/marginTopSmall"
android:visibility="invisible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/paddingStart"
android:id="@+id/lastConversationTitle"
android:text="@string/friends_important_title"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lastChatFriendsRecyclerView"
android:layout_below="@+id/lastConversationTitle"
android:layout_marginTop="@dimen/marginTopSmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/paddingStart"
android:layout_below="@+id/lastChatFriendsRecyclerView"
android:layout_marginTop="@dimen/marginTopSmall"
android:id="@+id/allFriendsTitle"
android:text="@string/friends_all"/>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/friendSwipeToRefresh"
android:layout_below="@+id/allFriendsTitle"
android:layout_marginTop="@dimen/marginTopSmall">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/friendsRecyclerView"
android:scrollbars="vertical"/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我的片段代码
private void setLastConversationFriendsRecycler(RecyclerView lastConversationRecyclerView, List<Edge<Friends>> friends){
lastConversationList.addAll(friends);
LinearLayoutManager …Run Code Online (Sandbox Code Playgroud)