0

I started using the Pagination Library and wanted to execute a background task using Work Manager on the loadInitial and loadAfter callbacks from the pagination library. The issue I was seeing was there was an issue with Work Manager dispatching multiple observers which caused my success / failure callbacks to trigger twice. The network operation would only be executed once, the issue was the callbacks were returning twice.

Executing a network operation in those callback functions (loadInitial & loadAfter) that does not use work manager (OKHTTP), it worked as expected with the return callbacks (failure & success) only getting called once.

Does Work Manager not work with Pagination? That is really disappointing if that is the case.

Has anyone else ran into this issue?

Mario Bouchedid
  • 431
  • 5
  • 7

1 Answers1

0

Can you please show us your code? In general, I don't think it makes sense to use WorkManager here - it's for deferrable execution, and I'm pretty sure you need that content right away.

SumirKodes
  • 551
  • 2
  • 6
  • Hey sorry for the delay in response.. I appreciate your comment. We are wrapping all our http network operations through WorkManager synchronously. However, when using an HTTP async request outside of work manager, it works as expected. The behavior was surprising to me. Also, due to confidentiality agreements with the client i work for, I am not able to post any specific code. I apologize for the inconvenience – Mario Bouchedid Aug 08 '19 at 04:01
  • 1
    I think you're using the wrong tool. You should using the HTTP requests independent of WorkManager. If you check the documentation, you will see that it says "WorkManager is intended for tasks that are deferrable—that is, not required to run immediately" (https://developer.android.com/topic/libraries/architecture/workmanager) – SumirKodes Aug 12 '19 at 19:32
  • Great feedback on this. I did some more research and it is in-fact not supposed to be used for all HTTP requests, but only in certain deferrable cases. I appreciate your input! – Mario Bouchedid Aug 14 '19 at 16:03