Forum Xamarin.Forms

How to approach an auto-synchronization when internet is back online?

BrianLKBrianLK Member ✭✭
edited March 27 in Xamarin.Forms

I am working on a Xamarin Forms application that allows you to submit Orders.

An order is composed with one ore multiple items, and an item can have many pictures.

To submit an Order to the server, these are the steps:

  • Make a request to create an Order. -> it returns the Order Id.
  • Make a request passing the list of items and the Order Id to create the Items. -> returns item ids.
  • Make a request for each picture using the corresponding item id.

The submission of the Order is working fine, but I have a use case were if there is no internet connection, the Orders enters in a "Pending to Submit" status, and when the device gets online again, it will automatically submit all the Orders with "Pending to Submit" status.

To do this, I have subscribed to the ConnectivityChanged event of the Xamarin Essentials Connectivity plugin, and when I detect that user has internet access, I start submitting each Order at a time. I don't know if there is a better solution to do this.

Also, there is a posibility that in the middle of a submission internet goes offline again, so maybe an Order was created, but the list of items are stuck in the middle without internet and the whole operation gets corrupted.

Any thoughts?


  • Daxton47Daxton47 Member ✭✭

    If these background tasks are running asynchronously, your ConnectivityChanged event should fire again once the user has gone back offline, right? You could cancel those tasks when you detect an offline state of connectivity AND there are "Submission" tasks being processed.

    The only alternative I see (and this is the way our enterprise app works) is that offline records are stored and have a similar "Pending" status for internet connection. When the user gets back an internet connection, they manually submit those pending orders, rather than the app automatically doing it for them. This gives the user a second chance to consider the submission which is a requirement for our app, but might not be for yours.

  • BrianLKBrianLK Member ✭✭

    Hi @Daxton47, as you said, we provided a button for manual submission, but they are keep asking for an automatic solution.

    About the suggestion you said, let me see if I understood, when an order is submitting (lets say "In Progress" status, if the user goes offline (the event triggers as you said), and I can detect that if there are any "In Progress" order, return the status to Pending again?

Sign In or Register to comment.