Hello Team,

We have a mobile app in which some server action called while offline sync but when mobile app gone to background in that case request failed and not completed.

Is there any way in mobile app to make some change,So that server request/offline sync process run background even when mobile app gone background.

Any suggestion?


Thanks,

Salman Ansari

Hi Salman,

In general, Mobile Apps don't and can't run in the background. Not saying there isn't a solution for your specific offline sync problem, but apart from that, there's no way to keep an app "alive" when it's not in the foreground.

Kilian Hekhuis wrote:

Hi Salman,

In general, Mobile Apps don't and can't run in the background. Not saying there isn't a solution for your specific offline sync problem, but apart from that, there's no way to keep an app "alive" when it's not in the foreground.


Hi Kilian,

Thank you for your quick response.

Could you please suggest any solution to my "specific offline sync problem"


Thanks,

Salman

No other than to make sure that the sync is done in such a way that it's done in small chuncks, so that when one chunck fails, you can restart that one and continue.

Hi Salman,

Adding to what Kilian mentioned, the only alternative would be to have a plugin to do that for you, since the JS running is suspended when the app goes to background.

Cheers,

RG

Kilian Hekhuis wrote:

No other than to make sure that the sync is done in such a way that it's done in small chuncks, so that when one chunck fails, you can restart that one and continue.

Hi,

Sync in chunk not possible in my case because we have approx.50000 records in local storage in one short,as this is the business need that they can scan any barcode from 50000 records and once barcode of product match from 50000 records then will display details screen of that product,So we have to sync all the 50000 records in local storage completely

Anyways thank you for your suggestion

Thanks,

Salman


Hi Salman,

I think I didn't explain correctly, so let me try again. Your problem is with the app going to the background. When the app is in the background, the user can't scan barcodes, so even if the sync at that moment has only synced 10000 records, that's no problem. As soon as the app is activated again, the sync can continue to run, until all 50000 records have been synced.

What you must make sure, and that's what I mean with "chunks", is that the sync doesn't need to restart all over (so the first 10000 records in the example above aren't sent again). If you send the data not all 50000 at a time, but say e.g. 1000 at a time, you can process the 1000, then the next 1000 and so on, and when the app goes to the background, at most 1000 records won't have been synced completely, so you can restart those 1000, fetch the next 1000 and so on.