我试图在我的应用程序中将我的 Paging 2 实现转换为带有 Flow 的 Paging 3,但受到“通道已关闭”异常的困扰。该应用程序运行良好,但一段时间后崩溃(从几秒钟到几分钟)。它从网络加载数据,这可能很慢。使用 Room 作为内部数据库。模拟器上的崩溃比真实设备上的要频繁得多。
我对 Flow 不熟悉,我应该注意 Flow 系统中是否有任何已知的罪魁祸首?
你们中的任何其他人在使用 androidx 的 Paging 3 时遇到过类似的情况吗?
因此,如果这是一个已知问题(可能有明显的修复),请给我一个提示;与否,我可能会发布 Paging 3 代码部分(这需要一些时间)。
我的异常如下所示:
2020-06-29 09:23:59.929 28295-28295/no.rogo.emptyfuel E/AndroidRuntime: FATAL EXCEPTION: main
Process: no.rogo.emptyfuel, PID: 28295
kotlinx.coroutines.channels.ClosedSendChannelException: Channel was closed
at kotlinx.coroutines.channels.Closed.getSendException(AbstractChannel.kt:1035)
at kotlinx.coroutines.channels.AbstractSendChannel.helpCloseAndResumeWithSendException(AbstractChannel.kt:206)
at kotlinx.coroutines.channels.AbstractSendChannel.access$helpCloseAndResumeWithSendException(AbstractChannel.kt:19)
at kotlinx.coroutines.channels.AbstractSendChannel.sendSuspend(AbstractChannel.kt:196)
at kotlinx.coroutines.channels.AbstractSendChannel.send(AbstractChannel.kt:135)
at kotlinx.coroutines.channels.ChannelCoroutine.send$suspendImpl(Unknown Source:2)
at kotlinx.coroutines.channels.ChannelCoroutine.send(Unknown Source:0)
at androidx.paging.PageFetcherSnapshot$pageEventFlow$1$2$invokeSuspend$$inlined$collect$1.emit(Collect.kt:137)
at kotlinx.coroutines.flow.FlowKt__ChannelsKt.emitAllImpl$FlowKt__ChannelsKt(Channels.kt:58)
at kotlinx.coroutines.flow.FlowKt__ChannelsKt$emitAllImpl$1.invokeSuspend(Unknown Source:11)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:69)
at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:184)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:108)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:308)
at kotlinx.coroutines.CancellableContinuationImpl.completeResume(CancellableContinuationImpl.kt:395)
at kotlinx.coroutines.channels.AbstractChannel$ReceiveElement.completeResumeReceive(AbstractChannel.kt:872)
at kotlinx.coroutines.channels.ConflatedChannel.offerInternal(ConflatedChannel.kt:61)
at kotlinx.coroutines.channels.ConflatedBroadcastChannel$Subscriber.offerInternal(ConflatedBroadcastChannel.kt:293)
at kotlinx.coroutines.channels.ConflatedBroadcastChannel.offerInternal(ConflatedBroadcastChannel.kt:255)
at kotlinx.coroutines.channels.ConflatedBroadcastChannel.offer(ConflatedBroadcastChannel.kt:236)
at androidx.paging.PageFetcherSnapshot.addHint(PageFetcherSnapshot.kt:189)
at androidx.paging.PageFetcher$PagerUiReceiver.addHint(PageFetcher.kt:118)
at androidx.paging.PagingDataDiffer$collectFrom$2$invokeSuspend$$inlined$collect$1$lambda$1.invokeSuspend(PagingDataDiffer.kt:93)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.UndispatchedCoroutine.afterResume(Builders.common.kt:214)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:113)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)